zoneddatetime

Convert ZonedDateTime to LocalDateTime at time zone

爱⌒轻易说出口 提交于 2020-01-12 06:44:26
问题 I have an object of ZonedDateTime that is constructed like this ZonedDateTime z = ZonedDateTime.of(LocalDate.now().atTime(11, 30), ZoneOffset.UTC); How can I convert it to LocalDateTime at time zone of Switzerland? Expected result should be 16 april 2018 13:30 . 回答1: How can I convert it to LocalDateTime at time zone of Switzerland? You can convert the UTC ZonedDateTime into a ZonedDateTime with the time zone of Switzerland, but maintaining the same instant in time, and then get the

Convert ZonedDateTime to LocalDateTime at time zone

狂风中的少年 提交于 2020-01-12 06:44:10
问题 I have an object of ZonedDateTime that is constructed like this ZonedDateTime z = ZonedDateTime.of(LocalDate.now().atTime(11, 30), ZoneOffset.UTC); How can I convert it to LocalDateTime at time zone of Switzerland? Expected result should be 16 april 2018 13:30 . 回答1: How can I convert it to LocalDateTime at time zone of Switzerland? You can convert the UTC ZonedDateTime into a ZonedDateTime with the time zone of Switzerland, but maintaining the same instant in time, and then get the

Java SQL Timestamp to ZonedDateTime

女生的网名这么多〃 提交于 2020-01-06 05:26:10
问题 I want to cast a ZonedDateTime object into a java.sql.Timestamp object without using the local date. For example, let's say I have the following datetime : System.out.println(myZonedDateTime); > 2018-09-02T23:55:05+04:00[Asia/Dubai] And my local timezone is UTC+08:00 I try to parse my ZonedDateTime to a Timestamp : Timestamp t = Timestamp.from(myZonedDateTime.toInstant()); System.out.println(t); > 2018-09-03 04:55:05.0 The value I get in my timestamp depends of my local time, when I want it

How to normalise ZonedDateTime so that .equals() works?

假装没事ソ 提交于 2020-01-04 00:19:49
问题 I have code, similar to this: import java.time._ object app { def main (args :Array[String]) = { println("app started") // create two ZonedDateTime objects for 1st Jan 2018, 10am UTC // using separate methods val zdt1 = ZonedDateTime.of(2018, 1, 1, 10, 0, 0, 0, ZoneId.of("UTC")) val zdt2 = ZonedDateTime.parse("2018-01-01T10:00:00Z") println(s"COMPARING: $zdt1 and $zdt2") println("== check: " + (zdt1 == zdt2)) println(".equals check: " + (zdt1.equals(zdt2))) println(".isEqual check " + (zdt1

ZonedDateTime to UTC with offset applied?

若如初见. 提交于 2020-01-01 10:07:56
问题 I am using Java 8 This is what my ZonedDateTime looks like 2013-07-10T02:52:49+12:00 I get this value as z1.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME) where z1 is a ZonedDateTime . I wanted to convert this value as 2013-07-10T14:52:49 How can I do that? 回答1: Is this what you want? This converts your ZonedDateTime to a LocalDateTime with a given ZoneId by converting your ZonedDateTime to an Instant before. LocalDateTime localDateTime = LocalDateTime.ofInstant(z1.toInstant(), ZoneOffset.UTC

ZonedDateTime to Date before Java 8 in early Android

蓝咒 提交于 2019-12-12 15:23:28
问题 I am trying to replace the ZonedDateTime.toInstant method because it is only available since API 26 for Android. But my app is supposed to support API 19. I want to convert the ZonedDateTime to a Date so i can do something like this: final Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); final long millis = calendar.getTimeInMillis(); What i want to achieve is the following: I want to calculate the difference between the current date and another date in Seconds,

converting epoch to ZonedDateTime in Java

可紊 提交于 2019-12-11 02:05:31
问题 How to convert epoch like 1413225446.92000 to ZonedDateTime in java? The code given expects long value hence this will throw NumberFormatException for the value given above. ZonedDateTime.ofInstant(Instant.ofEpochMilli(Long.parseLong(dateInMillis)), ZoneId.of(TIME_ZONE_PST)); 回答1: Basil Bourque’s answer is a good one. Taking out the nanoseconds from the fractional part into an integer for nanoseconds may entail a pitfall or two. I suggest: String dateInMillis = "1413225446.92000"; String[]

Mule - NoClassDefFoundError: Could not initialize class java.time.zone.ZoneRulesProvider

我是研究僧i 提交于 2019-12-10 19:37:36
问题 I've been trying to solve this problem without luck, hopefully someone could help me out... I created a DateUtil.java class which is placed within my project at: src/main/java/util/DateUtil.java I call "convertTime" method with the invoke component and on my laptop locally everything works fine but when deployed to an on-premise server I get the following error on the logs Root Exception stack trace: java.lang.NoClassDefFoundError: Could not initialize class java.time.zone.ZoneRulesProvider

Determine TimeZone from a JSON String?

◇◆丶佛笑我妖孽 提交于 2019-12-10 18:55:11
问题 I'm querying a JSON API that returns something like this: { "created_time": "2017-01-05T16:32:29+0100", "updated_time": "2017-01-11T09:38:41+0100", "id": "23842536731240607" } I need to store the times in UTC format, but in order to change the timezone, I first need to parse it as a ZonedDateTime . To convert "+0100" to "+01:00" is easy enough. But how can I parse the (created/updated)_time into a ZonedDateTime so I can convert it to UTC? 回答1: Well let me break down the problem statement.

Trying to parse a datetime in PDT to a ZonedDateTime representation

那年仲夏 提交于 2019-12-10 18:55:09
问题 How should I parse this datetime value that is in the PDT timezone? 06/24/2017 07:00 AM (PDT) I want to maintain the timezone so that I can then represent the time in other timezones depending on the website visitors preferences. I tried using ZonedDateTime but I get a parse error: java.time.ZonedDateTime.parse("06/24/2017 07:00 AM (PDT)") The error is: java.time.format.DateTimeParseException: Text '06/24/2017 07:00 AM (PDT)' could not be parsed at index 0 at java.time.format