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. SQL游标应用

    自己整了半天才弄好,写成博客纪念下: 这个是sql上写的测试用: ) ) ) ) declare @sql varchar(max) set @sql='' SET @type='index_02' ...

  2. 树形结构的数据库表Schema设计

    今天又有幸遇到一个不知道的东西,那就是树型结构在数据库表中设计的问题.由于只是阅读了人家的东西,就直接给连接吧. 第一个:http://blog.csdn.net/monkey_d_meng/arti ...

  3. 减少C++代码编译时间的方法

    c++ 的代码包含头文件和实现文件两部分, 头文件一般是提供给别人(也叫客户)使用的, 但是一旦头文件发生改变,不管多小的变化,所有引用他的文件就必须重新编译,编译就要花时间,假如你做的工程比较大(比 ...

  4. C# 单例模式Lazy<T>实现版本

    非Lazy版本的普通单例实现: public sealed class SingletonClass : ISingleton { private SingletonClass () { // the ...

  5. java 反编译和文档生成器

    挺有趣的东西. 代码在上一篇中有. 反编译器javap.exe javadoc.exe制作源文件类结构的html格式文档

  6. 数的n次方 s.match(reg) marquee滚动效果

    一.数的n次方 <script> alert(math.pow(a,5)); /*输出a的5次方*/ </script> 二. s.match(reg); s代表一个字符串,r ...

  7. PHP去除连续空格

    <?php $note = strip_tags($value['Content']); $note = trim($note); $note = str_replace(" &quo ...

  8. Java Swing的进化

    摘 要:Swing已是一个比较老的工具集了,在美观的用户界面出来之前需要开发很长时间.它缺少一些你在开发富UI时所需的组件.幸运地是,像 Substance,SwingX及Java Look-and_ ...

  9. Java-Eclipse插件开发学习笔记

    Eclipse插件 学习笔记 作者   Rick- Bao 开始日期  2014年8月26日 结束日期  2014年8月27日 一 . CVS(current version system) 版本控制 ...

  10. UVA 11552 四 Fewest Flops

    Fewest Flops Time Limit:2000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Statu ...