zoneddatetime

String to ZonedDateTime is changing format

人盡茶涼 提交于 2019-12-02 05:56:57
String ip="2011-05-01T06:47:35.422-05:00"; ZonedDateTime mzt = ZonedDateTime.parse(ip).toInstant().atZone(ZoneOffset.UTC); System.out.println(mzt); System.out.println("-----"); String ip2="2011-05-01T00:00:00.000-05:00"; ZonedDateTime mzt2 = ZonedDateTime.parse(ip2).toInstant().atZone(ZoneOffset.UTC); System.out.println(mzt2); Output: 2011-05-01T11:47:35.422Z ----- 2011-05-01T05:00Z Why is the date format getting changed in case 2? I am getting SQLServer Database error due to this. This is what toString from documentation said The format used will be the shortest that outputs the full value of

java.time.format.DateTimeParseException: Unable to obtain ZonedDateTime from TemporalAccessor on format ddMMyyyyhhmmss [duplicate]

笑着哭i 提交于 2019-12-02 03:59:43
This question already has an answer here: Unable to obtain ZonedDateTime from TemporalAccessor when parsing a Date 2 answers I'm having trouble in formatting a string to a ZonedDateTime. My customer wants to have the date in a format such as ddMMyyyyhhmmss, with no separators or stuff like that. This is what I've done so far import java.time.format.DateTimeFormatter; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZonedDateTime; public class MyClass { public static void main(String args[]) { DateTimeFormatter formatter = DateTimeFormatter.ofPattern("ddMMyyyyhhmmss");

How to convert any Date time to UTC using ZonedDateTime or Java 8

♀尐吖头ヾ 提交于 2019-11-30 10:01:36
I am trying to convert date 06-12-2015 02:10:10 PM from default zone to UTC using ZonedDateTime . LocalDateTime localDateTime = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()); ZonedDateTime utc = ZonedDateTime.of(localDateTime, ZoneOffset.UTC); but utc returns 2015-12-06T14:10:10Z instead of 06-12-2015 09:10:10 AM How can I convert date from default zone to UTC? The answer given here convert current time to UTC. You can use ZonedDateTime.ofInstant(Instant, ZoneId) where the second parameter is UTC (the instant knows the local offset). Something like, String source = "06-12

Java ZonedDateTime save in the Database

寵の児 提交于 2019-11-30 09:46:02
问题 I have a model object where I want to have a field with a date. For now I am using ZonedDateTime as it fits our needs. Hibernate stores this field in the database as a tinyblob . Can we change the way it is saved in the database to a more readable format and more importantly to a sortable format? The database used is a mysql db. 回答1: This issue has already been resolved as a new improvement to Hibernate 5.0.0.Beta1 , originally it was bundled in an isolated module hibernate-java8 Now it is

How to convert any Date time to UTC using ZonedDateTime or Java 8

旧城冷巷雨未停 提交于 2019-11-29 15:40:14
问题 I am trying to convert date 06-12-2015 02:10:10 PM from default zone to UTC using ZonedDateTime . LocalDateTime localDateTime = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()); ZonedDateTime utc = ZonedDateTime.of(localDateTime, ZoneOffset.UTC); but utc returns 2015-12-06T14:10:10Z instead of 06-12-2015 09:10:10 AM How can I convert date from default zone to UTC? The answer given here convert current time to UTC. 回答1: You can use ZonedDateTime.ofInstant(Instant, ZoneId)

Jackson deserialize date from Twitter to `ZonedDateTime`

耗尽温柔 提交于 2019-11-28 11:46:54
I want to deserialize date from Twitter to ZonedDateTime . My program fails on the created_at field deserializing. My Domain class @JsonIgnoreProperties(ignoreUnknown = true) public final class Tweet { public final String id; public final String idStr; public final ZonedDateTime created_at; public final String text; public final long timestamp_ms; public final User user; @JsonCreator public Tweet(@JsonProperty("id") String id, @JsonProperty("id_str") String idStr, @JsonProperty("created_at") ZonedDateTime created_at, @JsonProperty("text") String text, @JsonProperty("timestamp_ms") long

How to convert ZonedDateTime to Date?

只愿长相守 提交于 2019-11-28 03:45:22
I am trying to set a server agnostic date time in my database and I believe the best practice to do so is to set a UTC DateTime. My db server is Cassandra and the db driver for Java understands only the Date type. So assuming that in my code I am using the new Java 8 ZonedDateTime to get the UTC now ( ZonedDateTime.now(ZoneOffset.UTC) ), how can I convert this ZonedDateTime instance to the "legacy" Date class? Slim Soltani Dridi You can convert ZonedDateTime to an instant, which you can use directly with Date. Date.from(java.time.ZonedDateTime.now().toInstant()); tl;dr java.util.Date.from( //

Jackson deserialize date from Twitter to `ZonedDateTime`

荒凉一梦 提交于 2019-11-27 06:27:26
问题 I want to deserialize date from Twitter to ZonedDateTime . My program fails on the created_at field deserializing. My Domain class @JsonIgnoreProperties(ignoreUnknown = true) public final class Tweet { public final String id; public final String idStr; public final ZonedDateTime created_at; public final String text; public final long timestamp_ms; public final User user; @JsonCreator public Tweet(@JsonProperty("id") String id, @JsonProperty("id_str") String idStr, @JsonProperty("created_at")

How to convert ZonedDateTime to Date?

三世轮回 提交于 2019-11-27 00:05:10
问题 I am trying to set a server agnostic date time in my database and I believe the best practice to do so is to set a UTC DateTime. My db server is Cassandra and the db driver for Java understands only the Date type. So assuming that in my code I am using the new Java 8 ZonedDateTime to get the UTC now ( ZonedDateTime.now(ZoneOffset.UTC) ), how can I convert this ZonedDateTime instance to the "legacy" Date class? 回答1: You can convert ZonedDateTime to an instant, which you can use directly with