utc时间转毫秒
Posted 琅琊山二当家
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了utc时间转毫秒相关的知识,希望对你有一定的参考价值。
public class DateUtils private DateUtils() public static final String FORMAT_UTC = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; public static long formatUTCToLong(String utc) throws ParseException SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_UTC); Date parse = sdf.parse(utc); Calendar calendar = Calendar.getInstance(); calendar.setTime(parse); calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) + 8); return calendar.getTimeInMillis(); public static void main(String[] args) throws ParseException String FORMAT_UTC = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; String utc ="2022-11-15T14:00:08.996Z"; SimpleDateFormat sdf = new SimpleDateFormat(FORMAT_UTC); Date parse = sdf.parse(utc); Calendar calendar = Calendar.getInstance(); calendar.setTime(parse); calendar.set(Calendar.HOUR, calendar.get(Calendar.HOUR) + 8); System.out.println(formatUTCToLong("2022-11-15T14:00:08.996Z")); System.out.println(formatUTCToLong("2022-11-15T14:00:08.997Z")); System.out.println(formatUTCToLong("2022-11-15T14:00:09.000Z"));
输出效果
1668520808996
1668520808997
1668520809000
以上是关于utc时间转毫秒的主要内容,如果未能解决你的问题,请参考以下文章