zoneddatetime

Converting ZonedDateTime to string

こ雲淡風輕ζ 提交于 2020-06-23 11:00:41
问题 I need to store the current time as a String in a database. The time can be in different timezones, so I'm looking at using Java SE 8's new ZonedDateTime class. I notice that the toString() method automatically outputs: 2016-04-15T17:40:49.305-05:00[America/Chicago] This also seems to be readable by ZonedDateTime.parse() and convert to the right values. If all I am doing is storing these values and I don't need to ever convert the value to a user-readable format, is this all I need to do to

How to format a ZonedDateTime to a String?

北慕城南 提交于 2020-06-06 04:45:52
问题 I want to convert a ZonedDateTime to a String in the format of ("dd/MM/yyyy - hh:mm") . I know this is possible in Joda-Time other types, just using their toString("dd/MM/yyyy - hh:mm") ....But this doesn't work with ZonedDateTime.toString() . How can I format a ZonedDateTime to a String ? EDIT: I tried to print the time in another timezone and the result appears to be the same always: ZonedDateTime date = ZonedDateTime.now(); ZoneId la = ZoneId.of("America/Los_Angeles"); ZonedDateTime date2

How to format a ZonedDateTime to a String?

社会主义新天地 提交于 2020-06-06 04:44:30
问题 I want to convert a ZonedDateTime to a String in the format of ("dd/MM/yyyy - hh:mm") . I know this is possible in Joda-Time other types, just using their toString("dd/MM/yyyy - hh:mm") ....But this doesn't work with ZonedDateTime.toString() . How can I format a ZonedDateTime to a String ? EDIT: I tried to print the time in another timezone and the result appears to be the same always: ZonedDateTime date = ZonedDateTime.now(); ZoneId la = ZoneId.of("America/Los_Angeles"); ZonedDateTime date2

How to format a ZonedDateTime to a String?

纵然是瞬间 提交于 2020-06-06 04:44:12
问题 I want to convert a ZonedDateTime to a String in the format of ("dd/MM/yyyy - hh:mm") . I know this is possible in Joda-Time other types, just using their toString("dd/MM/yyyy - hh:mm") ....But this doesn't work with ZonedDateTime.toString() . How can I format a ZonedDateTime to a String ? EDIT: I tried to print the time in another timezone and the result appears to be the same always: ZonedDateTime date = ZonedDateTime.now(); ZoneId la = ZoneId.of("America/Los_Angeles"); ZonedDateTime date2

Convert a string to ZonedDateTime

空扰寡人 提交于 2020-05-17 07:44:15
问题 I need to convert the string 2020-04-15T23:00:00+0000 to a ZonedDateTime. I tried the below but they didnt work: DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss Z"); System.out.println(ZonedDateTime.parse("2020-04-15T23:00:00+0000", formatter)); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss 00:00"); System.out.println(ZonedDateTime.parse("2020-04-15T23:00:00+0000", formatter)); DateTimeFormatter formatter = DateTimeFormatter

ZonedDateTime.parse not working for parsing time with am or pm

爱⌒轻易说出口 提交于 2020-04-15 01:24:40
问题 I am learning java, trying to build a tool to convert a specific time from timezone A to timezone B based on user input (input of the time, timezone A, and timezone B). This is about the part where the tool gathers a time in a specific format to convert it into a ZonedDateTime object. import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.*; public static String fullTime; public static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm a");

ZonedDateTime ignores 00 for ss part

杀马特。学长 韩版系。学妹 提交于 2020-01-30 12:23:51
问题 I am trying to convert string value "2018-10-11T12:00:00Z"; to ZonedDateTime. If I use the default ZonedDateTime.parse(zonedDateTime) then ss portion i.e. 00 is removed and I get "2018-10-11T12:00Z" as output. Can you please help how to retain 00 as SS part. String zonedDateTime = "2018-10-11T12:00:00Z"; ZonedDateTime z = ZonedDateTime.parse(zonedDateTime); System.out.println(z); // return 2018-10-11T12:00Z ZonedDateTime z1 = ZonedDateTime.parse (zonedDateTime, DateTimeFormatter.ofPattern(

ZonedDateTime change behavior jdk 8/11

≡放荡痞女 提交于 2020-01-12 10:28:19
问题 I am migrating an application from jdk 8 to 11 and I can see ZonedDateTime change is behavior about daylight saving time. JDK8 ZonedDateTime parse = ZonedDateTime.parse("2037-05-10T19:15:00.000+01:00[Europe/Paris]"); System.out.println(parse); output: 2037-05-10T19:15+02:00[Europe/Paris] JDK11/12 ZonedDateTime parse = ZonedDateTime.parse("2037-05-10T19:15:00.000+01:00[Europe/Paris]"); System.out.println(parse); 2037-05-10T20:15+02:00[Europe/Paris] Can someone explain to me why did they change

ZonedDateTime change behavior jdk 8/11

穿精又带淫゛_ 提交于 2020-01-12 10:27:12
问题 I am migrating an application from jdk 8 to 11 and I can see ZonedDateTime change is behavior about daylight saving time. JDK8 ZonedDateTime parse = ZonedDateTime.parse("2037-05-10T19:15:00.000+01:00[Europe/Paris]"); System.out.println(parse); output: 2037-05-10T19:15+02:00[Europe/Paris] JDK11/12 ZonedDateTime parse = ZonedDateTime.parse("2037-05-10T19:15:00.000+01:00[Europe/Paris]"); System.out.println(parse); 2037-05-10T20:15+02:00[Europe/Paris] Can someone explain to me why did they change