| | |
| | | return new SimpleDateFormat("yyyy"); |
| | | } |
| | | }; |
| | | |
| | | public static final String STR_DATE = "yyyy-MM-dd"; |
| | | public static final String STRDATE = "yyyyMMdd"; |
| | | public static final String STR_YEAR_MONTH = "yyyy-MM"; |
| | | public static final String STRYEARMONTH = "yyyyMM"; |
| | | public static final String STR_DATE_TIME = "yyyy-MM-dd HH:mm:ss.SSS"; |
| | | public static final String STR_DATE_TIME_SMALL = "yyyy-MM-dd HH:mm:ss"; |
| | | public static final String STR_DD_MM_YYYY = "dd/MM/yyyy HH:mm:ss"; |
| | | public static final String STR_DATE_TIME_MIN = "yyyy-MM-dd HH:mm"; |
| | | public static final String STR_DATE_TIME_HOUR = "yyyy-MM-dd HH"; |
| | | public static final String STR_DATE_TIME_FULL = "yyyyMMddHHmmssSSS"; |
| | | public static final String STR_HHMMSS = "HH:mm:ss"; |
| | | public static final String STR_HHMM = "HH:mm"; |
| | | |
| | | public static String format(Date date, String format) { |
| | | SimpleDateFormat df = new SimpleDateFormat(format); |
| | | return df.format(date); |
| | | } |
| | | |
| | | public static String formattedDate(String dateString, String dateformat, String format) { |
| | | // 定义原始日期字符串和其格式 |
| | | SimpleDateFormat originalFormat = new SimpleDateFormat(dateformat); |
| | | // 定义目标日期格式 |
| | | SimpleDateFormat targetFormat = new SimpleDateFormat(format); |
| | | try { |
| | | // 解析原始日期字符串 |
| | | Date date = originalFormat.parse(dateString); |
| | | // 将日期格式化为目标格式 |
| | | String formattedDate = targetFormat.format(date); |
| | | |
| | | // 输出转换后的日期字符串 |
| | | System.out.println(formattedDate); |
| | | return formattedDate; |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 以毫秒表示的时间 |
| | | */ |