CST-UTC有多种转换方式,本次仅记录SimpleDateFormat的转换。

1. CST转UTC

当前时间转换为UTC标准时间格式,由于时区问题所以标准时间比北京时间慢8个小时。

public static String utcDateFormat() {SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));String localDateStr = simpleDateFormat.format(new Date(System.currentTimeMillis()));String currentTime = null;try {SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");Date date = simpleDateFormat1.parse(localDateStr);simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");currentTime = simpleDateFormat1.format(date);}catch (ParseException e) {e.printStackTrace();}return currentTime;
}

执行结果:

2. UTC转CST

2023-02-22T08:56:11Z转换为CST北京时间。

public static String CstDateFormat(String oldDateStr) {String convertTime = null;SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");try {simpleDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));//SimpleDateFormat只能格式化比自己精度长的时间,或者相同的时间精度,不能格式化比自己精度短的时间SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");convertTime = simpleDateFormat1.format(simpleDateFormat.parse(oldDateStr));} catch (ParseException e) {e.printStackTrace();}return convertTime;
}

Java中的CST-UTC时间格式相互转换相关推荐

  1. Java中字符串CST的时间日期转换

    在工作过程中,一些业务免不了接触到了一些对时间字符串的处理,整理如下: 转换诸如 " Wed, 17 Oct 2018 20:17:40 CST"," Wed, 17 O ...

  2. java 设置utc时间格式_UTC时间和北京时间(Java处理)

    1.时间说明 具体时间说明:https://blog.csdn.net/top_code/article/details/50462922 图借鉴上述链接中的内容: UTC时间:是世界标准的时间. 北 ...

  3. JAVA中获取当前系统时间

    JAVA中获取当前系统时间 转自:http://www.cnblogs.com/Matrix54/archive/2012/05/01/2478158.html 一. 获取当前系统时间和日期并格式化输 ...

  4. JAVA中获得前一天的时间

    JAVA中获得前一天的时间 public static void main(String[] args) {SimpleDateFormat sdf=new SimpleDateFormat(&quo ...

  5. java 正则表达式 判断 日期_怎么在java中利用正则表达式对时间日期进行判断

    怎么在java中利用正则表达式对时间日期进行判断 发布时间:2020-12-08 16:18:34 来源:亿速云 阅读:105 作者:Leah 这篇文章给大家介绍怎么在java中利用正则表达式对时间日 ...

  6. linux cst utc时间转换,Linux下CST和UTC时间的区别以及不一致的解决方法

    1.在linux中,用date查看时间的时候显示: 2013年 2月 17日 星期三 19:04:14 CST 世界协调时间(Universal Time Coordinated,UTC): GPS ...

  7. Java中获取日期和时间

    Java中获取日期和时间 1.创建 java.util.Calendar 实例,调用其 get()方法传入不同的参数即可获 得参数所对应的值 import java.util.Calender; // ...

  8. Java中[xxx:xxx,aaa:aaa]格式字符串解析

    Java中[xxx:xxx,aaa:aaa]格式字符串解析 String str = "[name:张三,age:18,phone:15888887777,email:15888887777 ...

  9. C# 本地时间格式,UTC时间格式,GMT时间格式处理

    一.本地时间显示 DateTime now = DateTime.Now; //本地时间格式 Console.WriteLine(now.ToLongDateString()); Console.Wr ...

  10. ant design vue 表格中时间戳转换成时间格式显示

    ant design vue 表格中时间戳转换成时间格式显示 原始数据表格如上图,因为接口传递过来的时间是10位int类型的时间戳格式,所以前端需要我们把时间格式化. step1 安装moment n ...

最新文章

  1. WINCE恢复默认HIVE注册表的方法
  2. spark源码分析之Executor启动与任务提交篇
  3. oracle设置no null,Oracle 在not in中使用null的问题
  4. #翻译#将像素绘制到屏幕上
  5. 集训8.19最短路径讲解
  6. (安卓)一键锁屏 ---亲测!
  7. C语言作业怎么答辩,c语言贪吃蛇如何答辩
  8. 华为铁三角作战的道法术,华为铁三角第一人,LTC专家许浩明老师讲授
  9. 霍金实在论中的实践论
  10. Ios 公司申请苹果账号
  11. 高中发表在论文计算机方面,高中计算机论文
  12. 阿里巴巴在知乎上又出事了
  13. 42表盘直径是从哪测量_手表表盘尺寸怎么量
  14. 酷狗音乐web端API接口数据
  15. SCTK计算lambda
  16. 杭电HDU 1004 Let the Balloon Rise AC代码 简单题
  17. 论文中文翻译——Automated Vulnerability Detection in Source Code Using Deep Representation Learning
  18. QT creater联机版斗地主斗地主(服务器与客户端两部分)
  19. 三台服务器搭建hadoop集群
  20. 【JS】1070- 8个工程必备的JavaScript代码片段(建议添加到项目中)

热门文章

  1. 五分钟小知识之什么是前缀表达式
  2. OpenGov(一):什么是Polkadot Gov2
  3. 数据结构你真的懂了吗?————「基础概念篇」
  4. 高德POI搜索:地点关键词搜索
  5. 基于单片机、RTOS玩MicroPython
  6. 18. 地下城与勇士
  7. 计算机科学的重要意义,论文开题报告计算机科学与技术的现代化运用,理论意义和现实意义,对现代社会的重要性,为什么要研究这个...
  8. [前端笔记037]vue2之vuex
  9. MATLAB中的一些方法
  10. 七.导航组件navigator