/***
 * 转成格林威治时间
 *
 * @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());
}

本地时间和格林威治时间转换相关推荐

  1. C语言之本地时间与格林威治时间互相转换(2种相互转换方法)

    格林威治时间转换显示 #include <stdio.h> #include <string.h> #include <time.h>typedef struct ...

  2. 美国洛杉矶时间转 格林威治时间

    /** 美国洛杉矶时间转 格林威治时间 */ function toTimeZone($src, $from_tz = 'America/Los_Angeles', $to_tz = 'Etc/GMT ...

  3. 关于utc时间与格林威治时间(linux上获取系统时区及代码)

    关于utc时间与格林威治时间 协调世界时,又称世界统一时间,世界标准时间,国际协调时间,简称UTC.它从英文"Coordinated Universal Time"/法文" ...

  4. 北京时间和格林威治时间互相转化 JavaScript

    // 1. 获取北京时间const currentDate = new Date()// 2.获取格林威治时间// 先获取当前所在国家和格林威治时间之间的差值,默认是分钟数// 使用Date对象的ge ...

  5. 获得当前时间的格林威治时间毫秒数

    搜的,备忘 select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') current_date, (sysdate- to_date('1970-01-01',' ...

  6. 日期格式:ddMMyy-hhmmss,格林威治时间转换成北京时间

    有些项目需要第三方的接口来取数据,这样就有个问题,那就是有些字段比较特殊,采用的都是国际标准时间,方便别的语言调用,这样时间差就相差不一样了,需要进行转换. 例如:GPS的数据时间格式:ddMMyy- ...

  7. 【Java】时差问题,格林威治时间(GMT)与北京时间转换

    格林威治时间加上8h即为北京时间 本文以格林威治时间转为北京时间为例,若需将北京时间转为格林威治时间只需将文中+8改为-8即可 1. 时间格式为:2021-01-04T04:16:23.609Z 此处 ...

  8. C语言北京时间与格林威治时间戳的转换

    时间戳是指格林威治时间自1970年1月1日(00:00:00 GTM)至当前时间的总秒数.它也被称为Unix时间戳(Unix Timestamp): 北京时间与格林威治时间有8小时偏差,28800秒: ...

  9. 格林威治时间转UTC

    场景: spirngwebflux 作为 微服务的 单元  与前端 ve 对接时 前端使用时间控件 传入到接口的时间给格林威治时间 解决方案: public static Timestamp gmtT ...

最新文章

  1. 记一次Weblogic连接池泄露的修复过程
  2. jquery01-简介+语法+选择器+事件
  3. 漫话:如何给女朋友解释什么是 3PC?
  4. 分享一个debian系统优秀的镜像源
  5. 串口驱动的3种实现方式
  6. 面向对象编程---掷骰子游戏
  7. 没有搭讪的人生是不完整的
  8. UVA-10246 - Asterix and Obelix(dijkstra)
  9. 最伟大的IT人物10强
  10. allegro中Externally Determined Violation错误标记去掉的skill
  11. 面试系列-3 限流场景实践
  12. LabVIEW控制Arduino采集多路模拟量、数字量(进阶篇—1)
  13. PPT转Word文档及word图片批量居中
  14. 【开发经验】java代码中实现限流
  15. 【开赛啦!邀你来战 】2022年“桂林银行杯”数据建模大赛暨全国大学生数学建模竞赛广西赛区热身赛
  16. python文件审计系统_Python系统审计-笔记
  17. Could not connect to SMTP host: smtp.***.com, port: 465, response: -1
  18. Vue中常见的性能优化,项目优化/单页面性能优化,Vue中六大优化方案
  19. huggingface transformers实战系列-06_文本摘要
  20. 2022-3-20 Leetcode 0402.最小高度树

热门文章

  1. 计算机基础在线上补考,大学计算机基础补考试卷
  2. 小米摄像头被谷歌紧急封禁!别人的设备,能看到你家现场
  3. 狗年出生的宝宝取名应该注意的4个问题
  4. 【excel】如何显示与取消表格中的打印虚线
  5. Android Studio 解决手机无法识别问题
  6. 导出wps表格 相当于换行的字符
  7. ae合成设置快捷键_LED显示屏怎么与 AE的合成设置匹配?
  8. 陈宁计算机辅助设计说课稿,《丑小鸭》说课稿
  9. win10应用商店无法下载应用,或者下载完无法安装(错误代码:0x80073D0A)
  10. 登录华为账户显示无法连接服务器,App提示连接不到服务器