| | |
| | | import java.text.DateFormat; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.ZonedDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.GregorianCalendar; |
| | |
| | | |
| | | /** |
| | | * 指定模式的时间格式 |
| | | * |
| | | * @param pattern |
| | | * @return |
| | | */ |
| | |
| | | } |
| | | return date2Str(date_sdf.get()); |
| | | } |
| | | /** |
| | | * 时间戳转换为字符串 |
| | | * |
| | | * @param time |
| | | * @return |
| | | */ |
| | | public static String timestamptoStr(Long time, SimpleDateFormat sdf) { |
| | | Date date = null; |
| | | if (null != time) { |
| | | date = new Date(time); |
| | | } |
| | | return date2Str(date, sdf); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 字符串转换时间戳 |
| | |
| | | |
| | | /** |
| | | * 将字符串转成时间 |
| | | * |
| | | * @param str |
| | | * @return |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * 特殊时间str转正常str |
| | | * |
| | | * @param st 2024-08-14T01:07:36.761+00:00 |
| | | * @return |
| | | */ |
| | | public static String zone2Str(String st) { |
| | | // 解析字符串为ZonedDateTime对象 |
| | | ZonedDateTime zonedDateTime = ZonedDateTime.parse(st); |
| | | // 转换为中国标准时间(UTC+8) |
| | | ZonedDateTime cstDateTime = zonedDateTime.withZoneSameInstant(java.time.ZoneOffset.ofHours(8)); |
| | | // 定义想要的输出格式 |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | // 格式化为想要的字符串 |
| | | String str = cstDateTime.format(formatter); |
| | | return str; |
| | | } |
| | | |
| | | /** |
| | | * 判断两个时间是否是同一年 |
| | | * |
| | | * @param date1 |