jodatime

How to remove timezone when convert from Date to DateTime

纵饮孤独 提交于 2021-02-11 17:19:27
问题 I have a Date get from Database and I want convert it to DateTime and set it to begin day. I write it below: Date fromDate = studentDateJoin.getDate(); //result: fromDate = Mon Jan 01 00:00:02 ICT 2018 //convert to DateTime DateTime newDate = new DateTime(fromDate); But when I convert it add time zone after convert. newDate look like : newDate = 2018-01-01T14:13:04.574Z+7 I have a question: How to convert it to begin day and remove timezone: Example I want to convert it look like: //Convert

How do I parse “YYYY-MM-DD” with joda time

只谈情不闲聊 提交于 2021-02-07 14:29:15
问题 I'm trying to use joda-time to parse a date string of the form YYYY-MM-DD . I have test code like this: DateTimeFormatter dateDecoder = DateTimeFormat.forPattern("YYYY-MM-DD"); DateTime dateTime = dateDecoder.parseDateTime("2005-07-30"); System.out.println(dateTime); Which outputs: 2005-01-30T00:00:00.000Z As you can see, the DateTime object produced is 30 Jan 2005 , instead of 30 July 2005 . Appreciate any help. I just assumed this would work because it's one of the date formats listed here.

How do I parse “YYYY-MM-DD” with joda time

ぃ、小莉子 提交于 2021-02-07 14:27:34
问题 I'm trying to use joda-time to parse a date string of the form YYYY-MM-DD . I have test code like this: DateTimeFormatter dateDecoder = DateTimeFormat.forPattern("YYYY-MM-DD"); DateTime dateTime = dateDecoder.parseDateTime("2005-07-30"); System.out.println(dateTime); Which outputs: 2005-01-30T00:00:00.000Z As you can see, the DateTime object produced is 30 Jan 2005 , instead of 30 July 2005 . Appreciate any help. I just assumed this would work because it's one of the date formats listed here.

How do I parse “YYYY-MM-DD” with joda time

你。 提交于 2021-02-07 14:27:24
问题 I'm trying to use joda-time to parse a date string of the form YYYY-MM-DD . I have test code like this: DateTimeFormatter dateDecoder = DateTimeFormat.forPattern("YYYY-MM-DD"); DateTime dateTime = dateDecoder.parseDateTime("2005-07-30"); System.out.println(dateTime); Which outputs: 2005-01-30T00:00:00.000Z As you can see, the DateTime object produced is 30 Jan 2005 , instead of 30 July 2005 . Appreciate any help. I just assumed this would work because it's one of the date formats listed here.

How to format a LocalTime variable

萝らか妹 提交于 2021-02-05 12:36:25
问题 I am quite new to Java windowbuilder, and this is part of my first project. String starttime = JOptionPane.showInputDialog(null, "What time would you like to start your revision ? (ie:12:24) "); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HH:mm"); LocalTime start = LocalTime.parse(starttime,dtf); I want to convert the format of start from ("HH:mm:ss..etc") to ("HH:mm") , but I get an error for the LocalTime.parse for some reason. Any suggestions what I should do. I'm using Joda Time

How to format a LocalTime variable

北慕城南 提交于 2021-02-05 12:33:33
问题 I am quite new to Java windowbuilder, and this is part of my first project. String starttime = JOptionPane.showInputDialog(null, "What time would you like to start your revision ? (ie:12:24) "); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("HH:mm"); LocalTime start = LocalTime.parse(starttime,dtf); I want to convert the format of start from ("HH:mm:ss..etc") to ("HH:mm") , but I get an error for the LocalTime.parse for some reason. Any suggestions what I should do. I'm using Joda Time

Convert a timestamp before year 1900 in java

送分小仙女□ 提交于 2021-01-28 01:07:56
问题 My Android app communicate with an API which give me the following timestamp : -2209161600 . Converted to a date time, it's supposed to be 12-30-1899 00:00:00 The problem is, I tried to convert this timestamp using both the default library, threetenbp, and then jodatime, but I always get the same wrong result, using Europe/Paris timezone : 12-30-1899 00:09:21 Why does that happen ? EDIT: For example with jodatime DateTime dt = new DateTime(-2209161600000L, DateTimeZone.forID("Europe/Paris"));

Serializing Joda DateTime object is creating different output depending on context

谁说胖子不能爱 提交于 2021-01-27 21:09:28
问题 I have an object in which is nested a Joda DateTime object, and I'm having trouble serializing it and deserializing it. When I serialize the full object that DateTime is nested in, the output looks vastly different than when I serialize the DateTime object directly, my results are below new ObjectMapper.writeValueAsString(fullObjectWithDateTime) produces the following blob for the DateTime object: { "dateTime": { "weekOfWeekyear": 34, "weekyear": 2019, "yearOfEra": 2019, "yearOfCentury": 19,

Error with Joda-Time in Android: The datetime zone id 'America/New_York' is not recognised

这一生的挚爱 提交于 2021-01-21 06:54:05
问题 Exception: Caused by: java.lang.IllegalArgumentException: The datetime zone id 'America/New_York' is not recognised Android code: DateTime dt = new DateTime(); DateTimeZone dtZone = DateTimeZone.forID("America/New_York"); DateTime dtus = dt.withZone(dtZone); Date dateInUS = dtus.toDate(); System.out.println(dateInUS); Why am I getting this error? I have loaded the Joda API in Gradle: compile 'net.danlew:android.joda:2.7.1' 回答1: I solved the error by adding: public void onCreate() { super

Error with Joda-Time in Android: The datetime zone id 'America/New_York' is not recognised

一笑奈何 提交于 2021-01-21 06:52:29
问题 Exception: Caused by: java.lang.IllegalArgumentException: The datetime zone id 'America/New_York' is not recognised Android code: DateTime dt = new DateTime(); DateTimeZone dtZone = DateTimeZone.forID("America/New_York"); DateTime dtus = dt.withZone(dtZone); Date dateInUS = dtus.toDate(); System.out.println(dateInUS); Why am I getting this error? I have loaded the Joda API in Gradle: compile 'net.danlew:android.joda:2.7.1' 回答1: I solved the error by adding: public void onCreate() { super