1. 格林威治时间即UTC/GMT时间,1970年01月01日00时00分00秒(即UTC+8的北京时间1970年01月01日08时00分00秒)
    计算代码如下:
  /**
* 获取指定时间到格林威治时间的秒数
* UTC:格林威治时间1970年01月01日00时00分00秒(UTC+8北京时间1970年01月01日08时00分00秒)
* @param time
* @return
*/
public static long diffSeconds(String time){
Calendar calendar = Calendar.getInstance(); calendar.clear();
Date datetime = DatetimeUtil.toDateByDate14(time);
calendar.setTime(datetime); TimeZone timeZone = TimeZone.getTimeZone("GMT+08:00");
calendar.setTimeZone(timeZone);
return calendar.getTimeInMillis()/1000;
} public static void main(String[] args) throws Exception { String datetime = DatetimeUtil.getDatetime();
System.out.println("=================方法一:calendar============================");
System.out.println(diffSeconds(datetime));
System.out.println("=================方法二:计算时间差============================");
System.out.println(DatetimeUtil.diffSeconds("19700101080000", datetime, DatetimeUtil.PATTERN_YYYYMMDDHHMMSS));
System.out.println("=================方法三:使用system============================");
System.out.println(System.currentTimeMillis()/1000);
}

 

  2. 用Java取指定时区的时间 北京时间,纽约时间,班加罗尔时间

 /**
* 取北京时间
* @return
*/
public static String getBeijingTime(){
return getFormatedDateString(8);
} /**
* 取班加罗尔时间
* @return
*/
public static String getBangaloreTime(){
return getFormatedDateString(5.5f);
} /**
* 取纽约时间
* @return
*/
public static String getNewyorkTime(){
return getFormatedDateString(-5);
} /**
* 此函数非原创,从网上搜索而来,timeZoneOffset原为int类型,为班加罗尔调整成float类型
* timeZoneOffset表示时区,如中国一般使用东八区,因此timeZoneOffset就是8
* @param timeZoneOffset
* @return
*/
public static String getFormatedDateString(float timeZoneOffset){
if (timeZoneOffset > 13 || timeZoneOffset < -12) {
timeZoneOffset = 0;
} int newTime=(int)(timeZoneOffset * 60 * 60 * 1000);
TimeZone timeZone;
String[] ids = TimeZone.getAvailableIDs(newTime);
if (ids.length == 0) {
timeZone = TimeZone.getDefault();
} else {
timeZone = new SimpleTimeZone(newTime, ids[0]);
} SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(timeZone);
return sdf.format(new Date());
}
 

Java 获取各时区时间,获取当前时间到格林威治时间1970年01月01日00时00分00秒的秒数的更多相关文章

  1. java8中计算两个日期时间LocalDateTime的时间差,格式化成xx年yy月zz日aa时bb分cc秒

    原则上应该适用Period来计算,因为他是专门为这种需求设计的.当时他只能计算到两个时间差的,年月日 传入参数Period.between(LocalDate,LocalDate) 这里是计算两个Lo ...

  2. 格林治时间,也就是返回从 UTC 1970 年 1 月 1 日午夜开始经过的毫秒数。

    格林治时间,也就是返回从 UTC 1970 年 1 月 1 日午夜开始经过的毫秒数. (* Delphi获取13位格林治时间实现方法, 与java中的java.lang.System.currentT ...

  3. 【基础篇】DatePickerDialog日期控件的基本使用(二) ——分别获取年、月、日、时、分

    项目步骤: 1.在Main.xml布局文件中定义对应的组件,Main.xml内容如下: <?xml version="1.0" encoding="utf-8&qu ...

  4. SQL获取当前日期的年、月、日、时、分、秒数据

    SQL Server中获取当前日期的年.月.日.时.分.秒数据: SELECT GETDATE() as '当前日期',DateName(year,GetDate()) as '年',DateName ...

  5. SQL Server中如何获取当前年,月,日,时,分,秒

    分类: SQL Server  select GETDATE() as '当前日期',DateName(year,GetDate()) as '年',DateName(month,GetDate()) ...

  6. java获取两个时间的相隔时间,包括年、月、日、时、分、秒

    public static final int YEAR_RETURN = 0;                    public static final int MONTH_RETURN = 1 ...

  7. iOS-获取当前时间的年、月、日、时、分、秒

    //获取当前时间02    NSDate *now = [NSDate date];03    NSLog(@”now date is: %@”, now);0405    NSCalendar *c ...

  8. SQL SERVER数据库,按年、月、日、时、分、秒计算两个时间字段之间的间隔时间样例

    使用DATEDIFF(取值,时间字段1,时间字段2) 举例: SELECT DATEDIFF(YEAR,DRYSJ,DCYSJ),* FROM YXHIS2019..TBZYBR2019 --SQL ...

  9. C# DateTimePicker控件获取他的年,月,日,时,分,秒

    CustomFormat属性设置为: yyyy-MM-dd HH:mm:ss 记住还要修改一个属性值,DateFormat属性 可选项改为Custom,默认是Long

  10. java为啥计算时间从1970年1月1日开始

    http://www.myexception.cn/program/1494616.html ————————————————————————————————————————————————————— ...

随机推荐

  1. Android开发中完全退出程序的三种方法

    参考: http://android.tgbus.com/Android/tutorial/201108/363511.shtml Android程序有很多Activity,比如说主窗口A,调用了子窗 ...

  2. Color Me Less 分类: POJ 2015-06-10 18:24 11人阅读 评论(0) 收藏

    Color Me Less Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 31693   Accepted: 15424 D ...

  3. ural 1106,二分图染色,DFS

    题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1106 乍一眼看上去,好像二分图匹配,哎,想不出和哪一种匹配类似,到网上查了一下,DFS染 ...

  4. wamp安装完更改关联浏览器

    "wampmanager.conf"文件修改的是关于中到官网的链接打开方式. "wampmanager.ini"修改的是左键菜单的打开方式. 修改完无效的话重启 ...

  5. Mysql 升级到 5.6 后插入语句时间字段报错:Incorrect datetime value: '' for column 'createtime'

    今天部署服务器项目运行,当遇见有时间数据对象的插入和更新操作的时候,就报错,如下: Caused by: com.mysql.jdbc.MysqlDataTruncation: Data trunca ...

  6. Struts2的标签库(二)——OGNL表达式

    Struts2的标签库(二) --OGNL表达式 1.Struts2中的OGNL表达式增加了ValueStack的支持. 注:ValueStack--实际上是一个容器对象,该对象在启动Struts2框 ...

  7. Linux下mysql备份 恢复

    转载自http://blog.chinaunix.net/uid-20577907-id-161611.html 比如我们要备份mysql中已经存在的名为linux的数据库,要用到命令mysqldum ...

  8. 关于JDK的配置

    ① 安装官网下载的相应JDK安装包. 现在官网主推JDK8,JDK7以及更老的版本需要注册才能提供下载链接. ② 比如个人下载的jdk7-xxx.exe,安装路径为C:\Program Files\J ...

  9. Django1.9 Python3.4出现Error loading MySQLdb

    linux Errorloading MySQLdb module: No module named MySQLdb 这是因为目前 MySQLdb 还不支持 python3.x ,开源无人维护哈 之前 ...

  10. [HDOJ3709]Balanced Number(数位dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3709 题意:求区间[L,R]内每一个数中是否存在一位,使得左边的各位数*距离=右边的各位数*距离(自己 ...