| | |
| | | package com.yami.trading.common.util; |
| | | |
| | | import org.apache.commons.lang3.time.DateFormatUtils; |
| | | |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.Instant; |
| | | import java.time.ZoneId; |
| | | import java.time.ZonedDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.GregorianCalendar; |
| | |
| | | public static long stringToMillSeconds(String dateString){ |
| | | return stringToDate(dateString,java.sql.Timestamp.class).getTime(); |
| | | } |
| | | |
| | | /** |
| | | * 把美国时区时间转为德国时区时间 |
| | | * @param date |
| | | * @return |
| | | */ |
| | | public static String convertToZonedDateTime(Date date){ |
| | | // 1. 将Date转换为UTC瞬时点(Instant) |
| | | Instant utcInstant = date.toInstant(); |
| | | |
| | | // 2. 绑定原始时区:明确该时间是纽约时区的时间 |
| | | ZoneId newYorkZone = ZoneId.of("America/New_York"); |
| | | ZonedDateTime newYorkZonedTime = ZonedDateTime.ofInstant(utcInstant, newYorkZone); |
| | | |
| | | // 3. 转换为德国时区(Europe/Berlin,自动处理夏令时) |
| | | ZoneId berlinZone = ZoneId.of("Europe/Berlin"); |
| | | ZonedDateTime berlinZonedTime = newYorkZonedTime.withZoneSameInstant(berlinZone); |
| | | |
| | | // 4. 格式化输出(例如:yyyy-MM-dd HH:mm:ss) |
| | | DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | return berlinZonedTime.format(formatter); |
| | | } |
| | | |
| | | } |