本地时间和格林威治时间转换
/*** * 转成格林威治时间 * * @param LocalDate 时间格式必须是yyyy-MM-dd HH:mm:ss * @return*/ public static String LocalToGTM(String LocalDate) { SimpleDateFormat format; format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH); Date result_date; long result_time = 0; if (null == LocalDate) { return LocalDate; } else { try { format.setTimeZone(TimeZone.getDefault()); result_date = format.parse(LocalDate); result_time = result_date.getTime(); format.setTimeZone(TimeZone.getTimeZone("GMT00:00")); return format.format(result_time); } catch (Exception e) { e.printStackTrace(); } } return LocalDate; } /*** * 将当前时间转成格林威治时间戳 * * @return*/ public static String localToGTM() { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ENGLISH); format.setTimeZone(TimeZone.getTimeZone("GMT00:00")); try { Date currDate = Calendar.getInstance().getTime(); XLog.e(XLog.TAG_GU, "转换前的时间:" + currDate.toString() + " : " + currDate.getTime()); long resultTime = currDate.getTime(); String newTime = format.format(resultTime); XLog.e(XLog.TAG_GU, "转换后的时间:" + newTime); SimpleDateFormat gmtformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()); gmtformat.setTimeZone(TimeZone.getDefault()); Date newDate = gmtformat.parse(newTime); XLog.e(XLog.TAG_GU, "转换后的时间2 : " + newDate.getTime()); return "" + newDate.getTime(); } catch (Exception e) { e.printStackTrace(); } return format.format(Calendar.getInstance().getTime()); }
本地时间和格林威治时间转换相关推荐
- C语言之本地时间与格林威治时间互相转换(2种相互转换方法)
格林威治时间转换显示 #include <stdio.h> #include <string.h> #include <time.h>typedef struct ...
- 美国洛杉矶时间转 格林威治时间
/** 美国洛杉矶时间转 格林威治时间 */ function toTimeZone($src, $from_tz = 'America/Los_Angeles', $to_tz = 'Etc/GMT ...
- 关于utc时间与格林威治时间(linux上获取系统时区及代码)
关于utc时间与格林威治时间 协调世界时,又称世界统一时间,世界标准时间,国际协调时间,简称UTC.它从英文"Coordinated Universal Time"/法文" ...
- 北京时间和格林威治时间互相转化 JavaScript
// 1. 获取北京时间const currentDate = new Date()// 2.获取格林威治时间// 先获取当前所在国家和格林威治时间之间的差值,默认是分钟数// 使用Date对象的ge ...
- 获得当前时间的格林威治时间毫秒数
搜的,备忘 select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') current_date, (sysdate- to_date('1970-01-01',' ...
- 日期格式:ddMMyy-hhmmss,格林威治时间转换成北京时间
有些项目需要第三方的接口来取数据,这样就有个问题,那就是有些字段比较特殊,采用的都是国际标准时间,方便别的语言调用,这样时间差就相差不一样了,需要进行转换. 例如:GPS的数据时间格式:ddMMyy- ...
- 【Java】时差问题,格林威治时间(GMT)与北京时间转换
格林威治时间加上8h即为北京时间 本文以格林威治时间转为北京时间为例,若需将北京时间转为格林威治时间只需将文中+8改为-8即可 1. 时间格式为:2021-01-04T04:16:23.609Z 此处 ...
- C语言北京时间与格林威治时间戳的转换
时间戳是指格林威治时间自1970年1月1日(00:00:00 GTM)至当前时间的总秒数.它也被称为Unix时间戳(Unix Timestamp): 北京时间与格林威治时间有8小时偏差,28800秒: ...
- 格林威治时间转UTC
场景: spirngwebflux 作为 微服务的 单元 与前端 ve 对接时 前端使用时间控件 传入到接口的时间给格林威治时间 解决方案: public static Timestamp gmtT ...
最新文章
- 记一次Weblogic连接池泄露的修复过程
- jquery01-简介+语法+选择器+事件
- 漫话:如何给女朋友解释什么是 3PC?
- 分享一个debian系统优秀的镜像源
- 串口驱动的3种实现方式
- 面向对象编程---掷骰子游戏
- 没有搭讪的人生是不完整的
- UVA-10246 - Asterix and Obelix(dijkstra)
- 最伟大的IT人物10强
- allegro中Externally Determined Violation错误标记去掉的skill
- 面试系列-3 限流场景实践
- LabVIEW控制Arduino采集多路模拟量、数字量(进阶篇—1)
- PPT转Word文档及word图片批量居中
- 【开发经验】java代码中实现限流
- 【开赛啦!邀你来战 】2022年“桂林银行杯”数据建模大赛暨全国大学生数学建模竞赛广西赛区热身赛
- python文件审计系统_Python系统审计-笔记
- Could not connect to SMTP host: smtp.***.com, port: 465, response: -1
- Vue中常见的性能优化,项目优化/单页面性能优化,Vue中六大优化方案
- huggingface transformers实战系列-06_文本摘要
- 2022-3-20 Leetcode 0402.最小高度树