Java中的CST-UTC时间格式相互转换
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时间格式相互转换相关推荐
- Java中字符串CST的时间日期转换
在工作过程中,一些业务免不了接触到了一些对时间字符串的处理,整理如下: 转换诸如 " Wed, 17 Oct 2018 20:17:40 CST"," Wed, 17 O ...
- java 设置utc时间格式_UTC时间和北京时间(Java处理)
1.时间说明 具体时间说明:https://blog.csdn.net/top_code/article/details/50462922 图借鉴上述链接中的内容: UTC时间:是世界标准的时间. 北 ...
- JAVA中获取当前系统时间
JAVA中获取当前系统时间 转自:http://www.cnblogs.com/Matrix54/archive/2012/05/01/2478158.html 一. 获取当前系统时间和日期并格式化输 ...
- JAVA中获得前一天的时间
JAVA中获得前一天的时间 public static void main(String[] args) {SimpleDateFormat sdf=new SimpleDateFormat(&quo ...
- java 正则表达式 判断 日期_怎么在java中利用正则表达式对时间日期进行判断
怎么在java中利用正则表达式对时间日期进行判断 发布时间:2020-12-08 16:18:34 来源:亿速云 阅读:105 作者:Leah 这篇文章给大家介绍怎么在java中利用正则表达式对时间日 ...
- linux cst utc时间转换,Linux下CST和UTC时间的区别以及不一致的解决方法
1.在linux中,用date查看时间的时候显示: 2013年 2月 17日 星期三 19:04:14 CST 世界协调时间(Universal Time Coordinated,UTC): GPS ...
- Java中获取日期和时间
Java中获取日期和时间 1.创建 java.util.Calendar 实例,调用其 get()方法传入不同的参数即可获 得参数所对应的值 import java.util.Calender; // ...
- Java中[xxx:xxx,aaa:aaa]格式字符串解析
Java中[xxx:xxx,aaa:aaa]格式字符串解析 String str = "[name:张三,age:18,phone:15888887777,email:15888887777 ...
- C# 本地时间格式,UTC时间格式,GMT时间格式处理
一.本地时间显示 DateTime now = DateTime.Now; //本地时间格式 Console.WriteLine(now.ToLongDateString()); Console.Wr ...
- ant design vue 表格中时间戳转换成时间格式显示
ant design vue 表格中时间戳转换成时间格式显示 原始数据表格如上图,因为接口传递过来的时间是10位int类型的时间戳格式,所以前端需要我们把时间格式化. step1 安装moment n ...
最新文章
- WINCE恢复默认HIVE注册表的方法
- spark源码分析之Executor启动与任务提交篇
- oracle设置no null,Oracle 在not in中使用null的问题
- #翻译#将像素绘制到屏幕上
- 集训8.19最短路径讲解
- (安卓)一键锁屏 ---亲测!
- C语言作业怎么答辩,c语言贪吃蛇如何答辩
- 华为铁三角作战的道法术,华为铁三角第一人,LTC专家许浩明老师讲授
- 霍金实在论中的实践论
- Ios 公司申请苹果账号
- 高中发表在论文计算机方面,高中计算机论文
- 阿里巴巴在知乎上又出事了
- 42表盘直径是从哪测量_手表表盘尺寸怎么量
- 酷狗音乐web端API接口数据
- SCTK计算lambda
- 杭电HDU 1004 Let the Balloon Rise AC代码 简单题
- 论文中文翻译——Automated Vulnerability Detection in Source Code Using Deep Representation Learning
- QT creater联机版斗地主斗地主(服务器与客户端两部分)
- 三台服务器搭建hadoop集群
- 【JS】1070- 8个工程必备的JavaScript代码片段(建议添加到项目中)