Guest User

Untitled

a guest
Jun 25th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. /**
  2. * 获取现在时间
  3. *
  4. * @return 返回时间类型 yyyy-MM-dd HH:mm:ss
  5. */
  6. public static Date getNowDate() {
  7. Date currentTime = new Date();
  8. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  9. String dateString = formatter.format(currentTime);
  10. ParsePosition pos = new ParsePosition(8);
  11. Date currentTime_2 = formatter.parse(dateString, pos);
  12. return currentTime_2;
  13. }
  14.  
  15.  
  16. /**
  17. * 获取现在时间
  18. *
  19. * @return返回字符串格式 yyyy-MM-dd HH:mm:ss
  20. */
  21. public static String getStringDate() {
  22. Date currentTime = new Date();
  23. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  24. String dateString = formatter.format(currentTime);
  25. return dateString;
  26. }
  27.  
  28.  
  29. /**
  30. * 获取现在时间
  31. *
  32. * @return 返回短时间字符串格式yyyy-MM-dd
  33. */
  34. public static String getStringDateShort() {
  35. Date currentTime = new Date();
  36. SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
  37. String dateString = formatter.format(currentTime);
  38. return dateString;
  39. }
  40.  
  41.  
  42. /**
  43. * 获取时间 小时:分;秒 HH:mm:ss
  44. *
  45. * @return
  46. */
  47. public static String getTimeShort() {
  48. SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss");
  49. Date currentTime = new Date();
  50. String dateString = formatter.format(currentTime);
  51. return dateString;
  52. }
Add Comment
Please, Sign In to add comment