Java中的夏令时问题
因为在用C#做项目的时候被夏令时坑过一回,所以这次将在java中的时区转换信息做一下记录,很简单
SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat outputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
inputFormat.setTimeZone(TimeZone.getTimeZone("Asia/Shanghai"));
outputFormat.setTimeZone(TimeZone.getTimeZone("America/New_York"));
String datetime = "2016-03-20 12:00:00";
System.out.println("In china :" + inputFormat.format(inputFormat.parse(datetime)));
System.out.println("In New York :" + outputFormat.format(inputFormat.parse(datetime)));
datetime = "2016-02-20 12:00:00";
System.out.println("In china :" + inputFormat.format(inputFormat.parse(datetime)));
System.out.println("In New York :" + outputFormat.format(inputFormat.parse(datetime)));
System.out.println(TimeZone.getDefault().getID());
经过两次输出可以看到,进入夏令时的3月20日与未进入夏令时的2月20日,时差分别是12和13小时,所以直接用TimeZone是一个很好的做法。代码的最后一句可以获取当地环境的时区id
Java中的夏令时问题的更多相关文章
- 夏令时 DST (Daylight Saving Time) java中的夏令时【转】
1916年,德国首先实行夏令时,英国因为怕德国会从中得到更大的效益,因此紧跟着也采取了夏令时 1986年至1991年,中华人民共和国在全国范围实行了六年夏令时 サマータイム 夏時間(日本现在没有实行夏 ...
- Java中夏令时带来的Date不一致问题 (转)
http://www.cnblogs.com/snake-hand/archive/2013/06/10/3131157.html 最近同事W发现使用Java Date创建日期,在不同的机器上执行,得 ...
- Java中的日期操作
在日志中常用的记录当前时间及程序运行时长的方法: public void inject(Path urlDir) throws Exception { SimpleDateFormat sdf = n ...
- Java中的Calendar日历用法详解
第一部分 Calendar介绍 public abstract class Calendar implements Serializable, Cloneable, Comparable<Cal ...
- [转载]java中Date,SimpleDateFormat
一.Java中的日期概述: 日期在Java中是一块非常复杂的内容,对于一个日期在不同的语言国别环境中,日期的国际化,日期和时间之间的转换,日期的加减运算,日期的展示格式都是非常复杂的问题. 在Java ...
- Java中的日期操作 分类: B1_JAVA 2015-02-16 17:55 6014人阅读 评论(0) 收藏
在日志中常用的记录当前时间及程序运行时长的方法: public void inject(Path urlDir) throws Exception { SimpleDateFormat sdf = n ...
- Java中时间API使用详解
目录 Java中时间API使用详解 1. 时区概念 2. 几种常见的时间 3. 时间戳 4. Java中的时间API 5. Java8中新添加的时间API 6. 在东八区的机器上获得美国时间 Java ...
- Java中Date时区的转换
1.Date中保存的是什么? 在java中,只要我们执行 Date date = new Date(); 就可以得到当前时间.如: Date date = new Date(); System.ou ...
- Java中的Date和时区转换
1.Date中保存的是什么 在java中,只要我们执行 Date date = new Date(); 就可以得到当前时间.如: Date date = new Date(); System.out. ...
随机推荐
- spring 注解
@Qualifier("XXX") 中的 XX是 Bean 的名称,所以 @Autowired 和 @Qualifier 结合使用时,自动注入的策略就从 byType 转变成 by ...
- error LNK2019:unresolved external symbol
error LNK2019:unresolved external symbol 这个错误是指程序不认识函数.具体的说就是.h文件中定义并没有实现,这就是库出现了问题. 遇到这个问题,第一步就要看是哪 ...
- JS中修改属性
<!DOCTYPE html><html><head> <meta http-equiv="Content-Type" content=& ...
- Cannot add Controls from 64-bit Assemblies to the Toolbox or Use in Designers Within the Visual Studio IDE
原文地址:https://support.microsoft.com/en-us/kb/963017 Source: Microsoft Support RAPID PUBLISHING RAPID ...
- Swift - 设置tableView每个分区cell圆角
1.// 重新绘制cell边框 func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRow ...
- 笔记本双系统XP与Ubuntu,重装XP后如何恢复grup引导,另附操作系统启动过程
背景:笔记本双系统(XP与Ubuntu),其中XP系统因问题重装了一下,重装后不能识别Ubuntu系统(该系统装在另一个磁盘中),直接进入了XP系统. 解决办法:利用U盘(Ubuntu系统)启动机器, ...
- angular 依赖注入原理
依赖注入(Dependency Injection,简称DI)是像C#,java等典型的面向对象语言框架设计原则控制反转的一种典型的一种实现方式,angular把它引入到js中,介绍angular依赖 ...
- 【leetcode】Evaluate Reverse Polish Notation
Evaluate Reverse Polish Notation 题目描述: Evaluate the value of an arithmetic expression in Reverse Pol ...
- 取两个DataTable的交集,删除重复数据
/// <summary> /// 取两个DataTable的交集,删除重复数据 /// </summary> /// <param name="sourceD ...
- intellij idea使用
第02章 IntelliJ IDEA起步 熟悉IntelliJ IDEA用户界面 05 状态条 如何使用intellij idea 从Eclipse转移到IntelliJ IDEA一点心得 Intel ...