Tag: timezone

java时区setDefault效果

以下如何使用JPA和Hibernate以UTC时区存储日期/时间和时间戳我想将我的应用程序默认时区设置为UTC。 我的应用程序在Linux服务器上运行tomcat以及其他一些应用程序。 服务器有其他运行更多应用程序的tomcat实例。 Timezone.setDefault(tz)会影响同一个tomcat实例上的其他应用吗? 它会影响其他tomcat实例上的其他应用程序吗? 是否可以仅为应用设置时区? 我松散地记得有关安全管理器设置的一些内容。

跨TimeZone的Java Quartz-Scheduler

我的服务器在欧洲/罗马时区运行 – 这个是服务器上的默认tz,我需要根据用户的时区安排工作,因此,如果居住在Pacific / Honolulu时区的用户安排一个CronTrigger,每个人都会触发我发现这个解决方案的一天是晚上22点为他的地球区域: CronTrigger trigger = newTrigger() .withIdentity(“name”, “group”) .withSchedule( cronSchedule(“0 0 22 ? * *”).inTimeZone(TimeZone.getTimeZone(“Pacific/Honolulu”)) ) .startNow() .build(); 在我的服务器上,这项工作从第二天“我的”上午09:00开始 。 除了保持更新时区(即时区更新工具 )之外,还有一些特殊问题需要考虑吗? 如果我想为上一个作业定义.startAt()和.endAt(),这种日期是否正常? 使用此程序可以安全地使用夏令时吗? Calendar calTZStarts = new GregorianCalendar(TimeZone.getTimeZone(“Pacific/Honolulu”)); calTZStarts.set(2013, Calendar.JANUARY, 10); Calendar calTZEnds = new GregorianCalendar(TimeZone.getTimeZone(“Pacific/Honolulu”)); calTZEnds.set(2013, Calendar.JANUARY, 30); Calendar calStarts = Calendar.getInstance(); calStarts.set(Calendar.YEAR, calTZStarts.get(Calendar.YEAR)); calStarts.set(Calendar.MONTH, calTZStarts.get(Calendar.MONTH)); calStarts.set(Calendar.DAY_OF_MONTH, calTZStarts.get(Calendar.DAY_OF_MONTH)); calStarts.set(Calendar.HOUR_OF_DAY, calTZStarts.get(Calendar.HOUR_OF_DAY)); […]

从SimpleTimeZone获取ZoneId

使用Java我有一个带有GMT偏移量的SimpleTimeZone实例和来自遗留系统的夏令时信息。 我想检索ZoneId以便能够使用Java 8时间API。 实际上, toZoneId返回没有夏令时信息的ZoneId SimpleTimeZone stz = new SimpleTimeZone( 2 * 60 * 60 * 1000, “GMT”, Calendar.JANUARY,1,1,1, Calendar.FEBRUARY,1,1,1, 1 * 60 * 60 * 1000); stz.toZoneId();

MySQL – 如何用正确的时区存储时间? (来自Java)

我正在使用MySQL 5.0。 我需要将日期时间信息存储在一列中。 我的意思是使用DATETIME或TIMESTAMP列类型。 但我有夏季 – 冬季时间变化的问题。 我的时区是CET。 夏天我们使用夏令时(CEST,它是GMT + 2),冬天我们使用冬季时间(CET,它是GMT + 1)。 在夏季时间变为冬季的那一天(2012年是在10月28日)我们有时间凌晨2点两次。 这一天的时间顺序是: … -> 1:00 CEST -> 2:00 CEST -> 2:00 CET (= 3:00 CEST) -> 3:00 CET -> … 所以,如果我有时间戳/日期时间’2012-10-28 02:00:00’如果此时间代表夏令时或冬季时间凌晨2点,我无法正确说出。 我有两个不同的Java日期: Date d1 = new Date(1351382400000); // 2:00 CEST (summer-time) Date d2 = new Date(1351386000000); // 2:00 CET (winter-time) 当我使用标准时间戳/日期时间格式(即’yyyy-MM-dd […]

无法使用Java 8中的DateTimeFormatter和ZonedDateTime从TemporalAccessor获取ZonedDateTime

我最近转向Java 8,希望能更轻松地处理本地和分区时间。 但是,在我看来,在解析一个简单的日期时,我面临一个简单的问题。 public static ZonedDateTime convertirAFecha(String fecha) throws Exception { DateTimeFormatter formatter = DateTimeFormatter.ofPattern( ConstantesFechas.FORMATO_DIA).withZone( obtenerZonaHorariaServidor()); ZonedDateTime resultado = ZonedDateTime.parse(fecha, formatter); return resultado; } 就我而言: fecha是’15 / 06/2014′ ConstantesFechas.FORMATO_DIA是’dd / MM / yyyy’ obtenerZonaHorariaServidor返回ZoneId.systemDefault() 所以,这是一个简单的例子。 但是,解析会抛出此exception: java.time.format.DateTimeParseException: Text ’15/06/2014′ could not be parsed: Unable to obtain ZonedDateTime from TemporalAccessor: {},ISO resolved to 2014-06-15 of […]

有没有办法用(仅)国家代码(有效的ISO-3166代码)获得时区?

我正在尝试为用户获取TimeZone。 为此,我有一个国家代码,这是一个有效的ISO国家代码。 这些代码是ISO-3166定义的大写双字母代码。 您可以在多个站点找到这些代码的完整列表,例如: http : //www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html 我认为回应是“不,因为这是一个多方面的关系……像美国这样的国家可能有很多时区……”。 那就是问题所在… 我尝试过类似的东西: //CountryEnum contains ISO_3166 values (http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html) //List all country to test timezone: for (int i = 0; i < CountryEnum.values().length; i++) { String isoCountryCode = CountryEnum.values()[i].name();// Get the iso country code Locale locale = new Locale(isoCountryCode);// Build a country specific locale Calendar calendar = Calendar.getInstance(locale);// Build […]

Joda Time – 时区之间的差异

我想用Joda时间将当前时间转换为特定时区的时间。 有没有办法将DateTime time = new DateTime()转换为特定时区,或者可能是为了得到time.getZone()和另一个DateTimeZone之间的小时数差异,然后再做time.minusHours或time.plusHours ?

日期TimeZone在java中的转换?

我一直在寻找将格林威治标准时间转换为当地时间的最简单方法。 当然,要考虑适当的DST日期并尽可能标准。 我能想出的最直接的代码是: SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”); String inpt = “2011-23-03 16:40:44”; Date inptdate = null; try { inptdate = sdf.parse(inpt); } catch (ParseException e) {e.printStackTrace();} Calendar tgmt = new GregorianCalendar(TimeZone.getTimeZone(“GMT”)); tgmt.setTime(inptdate); Calendar tmad = new GregorianCalendar(TimeZone.getTimeZone(“Europe/Madrid”)); tmad.setTime(inptdate); System.out.println(“GMT:\t\t” + sdf.format(tgmt.getTime())); System.out.println(“Europe/Madrid:\t” + sdf.format(tmad.getTime())); 但我认为我没有得到getTime将返回的正确概念。

在Java中将本地时间戳转换为UTC时间戳

我有一个毫秒 – 自 – 本地 – 纪元时间戳,我想将其转换为毫秒自UTC时间戳。 从快速浏览文档看起来像这样的东西会起作用: int offset = TimeZone.getDefault().getRawOffset(); long newTime = oldTime – offset; 有一个更好的方法吗?

Java 8:计算两个ZonedDateTime之间的差异

我正在尝试编写一种方法来打印两个ZonedDateTime之间的时差 ,关于时区之间的差异。 我找到了一些解决方案,但所有这些解决方案都是用LocalDateTime编写的。