Obtain the current year, month, day, hour, minute, second, millisecond respectively

From , 2 Years ago, written in Java, viewed 231 times.
URL https://pastebin.vip/view/1aa48fc4
  1.     /**
  2.      * 英文简写(默认)如:2010-12-01
  3.      */
  4.     public static String FORMAT_SHORT = "yyyy-MM-dd";
  5.    
  6.     /**
  7.      * 英文全称  如:2010-12-01 23:15:06
  8.      */
  9.     public static String FORMAT_LONG = "yyyy-MM-dd HH:mm:ss";
  10.    
  11.     /**
  12.      * 精确到毫秒的完整时间    如:yyyy-MM-dd HH:mm:ss.S
  13.      */
  14.     public static String FORMAT_FULL = "yyyy-MM-dd HH:mm:ss.S";
  15.    
  16.     /**
  17.      * 中文简写  如:2010年12月01日
  18.      */
  19.     public static String FORMAT_SHORT_CN = "yyyy年MM月dd";
  20.    
  21.     /**
  22.      * 中文全称  如:2010年12月01日  23时15分06秒
  23.      */
  24.     public static String FORMAT_LONG_CN = "yyyy年MM月dd日  HH时mm分ss秒";
  25.    
  26.     /**
  27.      * 精确到毫秒的完整中文时间
  28.      */
  29.     public static String FORMAT_FULL_CN = "yyyy年MM月dd日  HH时mm分ss秒SSS毫秒";
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. /**
  39.    * 获取时间戳
  40.    */
  41. public static String getTimeString() {
  42.     SimpleDateFormat df = new SimpleDateFormat(FORMAT_FULL);
  43.     Calendar calendar = Calendar.getInstance();
  44.     return df.format(calendar.getTime());
  45. }
  46.  
  47. /**
  48.  * 获取日期年份
  49.  * @param date 日期
  50.  * @return
  51.  */
  52. public static String getYear(Date date) {
  53.     return format(date).substring(0, 4);
  54. }
  55. /**
  56.  * 功能描述:返回月
  57.  *
  58.  * @param date
  59.  *            Date 日期
  60.  * @return 返回月份
  61.  */
  62. public static int getMonth(Date date) {
  63.     calendar = Calendar.getInstance();
  64.     calendar.setTime(date);
  65.     return calendar.get(Calendar.MONTH) + 1;
  66. }
  67.  
  68. /**
  69.  * 功能描述:返回日
  70.  *
  71.  * @param date
  72.  *            Date 日期
  73.  * @return 返回日份
  74.  */
  75. public static int getDay(Date date) {
  76.     calendar = Calendar.getInstance();
  77.     calendar.setTime(date);
  78.     return calendar.get(Calendar.DAY_OF_MONTH);
  79. }
  80.  
  81. /**
  82.  * 功能描述:返回小
  83.  *
  84.  * @param date
  85.  *            日期
  86.  * @return 返回小时
  87.  */
  88. public static int getHour(Date date) {
  89.     calendar = Calendar.getInstance();
  90.     calendar.setTime(date);
  91.     return calendar.get(Calendar.HOUR_OF_DAY);
  92. }
  93.  
  94. /**
  95.  * 功能描述:返回分
  96.  *
  97.  * @param date
  98.  *            日期
  99.  * @return 返回分钟
  100.  */
  101. public static int getMinute(Date date) {
  102.     calendar = Calendar.getInstance();
  103.     calendar.setTime(date);
  104.     return calendar.get(Calendar.MINUTE);
  105. }
  106.  
  107. /**
  108.  * 返回秒钟
  109.  *
  110.  * @param date
  111.  *            Date 日期
  112.  * @return 返回秒钟
  113.  */
  114. public static int getSecond(Date date) {
  115.     calendar = Calendar.getInstance();
  116.     calendar.setTime(date);
  117.     return calendar.get(Calendar.SECOND);
  118. }
  119.  
  120. /**
  121.  * 功能描述:返回毫
  122.  *
  123.  * @param date
  124.  *            日期
  125.  * @return 返回毫
  126.  */
  127. public static long getMillis(Date date) {
  128.     calendar = Calendar.getInstance();
  129.     calendar.setTime(date);
  130.     return calendar.getTimeInMillis();
  131. }

Reply to "Obtain the current year, month, day, hour, minute, second, millisecond respectively"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website