| | |
| | | |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Date; |
| | | import java.util.Locale; |
| | | import java.util.TimeZone; |
| | | |
| | | public class TimeUtil { |
| | | public static void main(String[] args) { |
| | | String str = "PACK.OP360.ModuleSNCode1"; |
| | | System.out.println(str.charAt(str.length()-1)); |
| | | String dateString = "Tue May 14 18:25:18 CST 2024"; |
| | | // System.out.println(test(dateString)); |
| | | |
| | | System.out.println(test( stringProcessing("DateTime{utcTime=133601559184960000, javaDate=Tue May 14 18:25:18 CST 2024}"))); |
| | | } |
| | | |
| | | public static String stringProcessing(String dateTimeStr){ |
| | |
| | | String outputDate = formatter.format(date); |
| | | return outputDate; |
| | | } |
| | | |
| | | public static String test(String param){ |
| | | String str = ""; |
| | | // 创建一个SimpleDateFormat对象来解析输入的日期字符串(假设CST为中国标准时间) |
| | | SimpleDateFormat inputFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); |
| | | inputFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai")); // 设置为中国时区 |
| | | |
| | | Date date = null; |
| | | try { |
| | | date = inputFormat.parse(param); |
| | | } catch (ParseException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | // 创建一个SimpleDateFormat对象来格式化日期为UTC时间 |
| | | SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | outputFormat.setTimeZone(TimeZone.getTimeZone("UTC")); // 设置为UTC时区 |
| | | |
| | | // 格式化日期 |
| | | if (date != null) { |
| | | str = outputFormat.format(date); |
| | | } |
| | | return str; |
| | | } |
| | | |
| | | |
| | | |
| | | } |