jodatime

How can I get the number of days in a year using JodaTime?

别说谁变了你拦得住时间么 提交于 2019-12-10 14:45:40
问题 I've tried the following to no avail: new Period(Years.ONE).getDays(); new Period(1, 0, 0, 000).getDays(); The answer I want is obviously 365. 回答1: If you want the real number of days for a given year: int year = 2012; LocalDate ld = new LocalDate(year,1,1); System.out.println(Days.daysBetween(ld,ld.plusYears(1)).getDays()); Of course, this returns 365 or 366... normally: int year = 1582; LocalDate ld = new LocalDate(year,1,1,GJChronology.getInstance()); System.out.println(Days.daysBetween(ld

Limit Time Range in Time Picker

谁说胖子不能爱 提交于 2019-12-10 14:17:31
问题 How to control TimePicker, I just want to show time range in time picker from 08:00 am to 02:00 pm (except from 08:00 am to 02:00 pm hide all) I have written complete code to show TimePicker, and customized time as well. Here is my code: case DIALOG_TIME: final Calendar c = Calendar.getInstance(); int hour = c.get(Calendar.HOUR_OF_DAY); int minute = c.get(Calendar.MINUTE); // Create a new instance of TimePickerDialog and return it return new TimePickerDialog(this, lisTime, hour, minute,

Spring @RequestParam DateTime format as ISO 8601 Date Optional Time

╄→尐↘猪︶ㄣ 提交于 2019-12-10 13:22:22
问题 I'm using Spring Framework for my services API and org.joda.time.DateTime for datetime parsing. Specifically, I'm using the ISOFormatter.dateOptionalTimeParser() , which allows users the flexibility to use just the date, or both date and time, which is a requirement. Believe me, I've seen all these related questions that I can already tell people are going to point me towards, e.g. this and this, etc. Previously, I was taking the date as String and then processing it using the joda formatter

Joda time's DateTime converted to java.util.Date strange issue

让人想犯罪 __ 提交于 2019-12-10 12:38:03
问题 I ran into a strange issue. Here is a snippet of code that describes it: DateTimeZone dtz = DateTimeZone.forOffsetHours(0); DateTime dt = new DateTime(dtz); System.out.println(dt); System.out.println(dt.toDate()); the output is: 2012-02-29T17:24:39.055Z Wed Feb 29 19:24:39 EET 2012 I'm located UTC+2, but this action is supposed to create a java.util.Date object which is initialized for UTC time. What am I missing? 回答1: Date doesn't know about a time zone at all - it only represents an instant

Round time by seconds

你离开我真会死。 提交于 2019-12-10 12:15:18
问题 In my Java project I want round Date time seconds which is divided by 5. I have got - I want 12:00:01 - 12:00:00 12:00:04 - 12:00:05 12:00:06 - 12:00:05 12:00:07 - 12:00:05 12:00:08 - 12:00:10 ... 12:00:58 - 12:01:00 Date object contain date for example: Fri May 12 12:00:03 CEST 2017 and I want round seconds to modulo 5. I want achieve Date object with rounded seconds. How can I do this using simple math or Joda ? 回答1: Here’s a suggestion: LocalTime time = LocalTime.now(ZoneId.systemDefault()

Current datetime in Joda-Time date formatting for mysql timestamp

▼魔方 西西 提交于 2019-12-10 11:19:56
问题 I need to import the current date and time into a MySQL database field whose format is TimeStamp. From examining sample data, it seems that the format for the MySQL TimeStamp datatype is "yyyy-mm-dd hh:mm:ss". I am using Joda-Time formatting in my spring hibernate application. How do I get the current date time in a format that will be accepted by the underlying MySQL TimeStamp formatted field? Here is my current code, which will not compile because eclipse says .parseDateTime() requires a

How to force Joda-Time to parse only part of String?

被刻印的时光 ゝ 提交于 2019-12-10 11:09:33
问题 let's assume I have following dates (in String): 2009-05-15T23:00:00 2009-05-15T23:00:00.000Z 2009-05-15 I don't care about the time and zone, only date is relevant for me. So I want to try to parse it with following pattern: yyyy-MM-dd I try to parse it using Joda-Time: DateTimeFormat = DateTimeFormat.forPattern("yyyy-MM-dd"); format.withZone(zone).parseDateTime(string).toLocalDate(); and I get following exception: java.lang.IllegalArgumentException: Invalid format: "2009-05-15T23:00:00.000Z

Duration with daylight saving

梦想的初衷 提交于 2019-12-10 10:55:40
问题 I have an object Shift , with two fields: startDateTime and endDateTime as DateTime from Joda-Time. And my shift includes Daylight Saving UK change. It starts on 25/03/2017 13:00 and ends on 26/03/2017 02:00 (basically should end on 26/03/2017 01:00 , but this date does not exists, and endDate is shifted +1 hour). According to this site: When local standard time was about to reach Sunday, 26 March 2017, 01:00:00 clocks were turned forward 1 hour to Sunday, 26 March 2017, 02:00:00 local

Joda Time - Hibernate inserts yesterday's date into database

本小妞迷上赌 提交于 2019-12-10 10:48:27
问题 I'm having a weird problem right now. When I insert todays date into database, it's mapped into yesterdays date, it happens with every date. For example, when I try to insert 2016-09-02, database saves it as 2016-09-01. Here is my mapping: @DateTimeFormat(pattern="dd/MM/yyyy") @Column(name = "OrderDate", nullable = false) @Type(type="org.jadira.usertype.dateandtime.joda.PersistentLocalDate") private final LocalDate orderDate; I create instances by new LocalDate() I tried printing the value on

Convert string with form “MM/dd/yyyy HH:mm” to joda datetime in dataframe in Spark

我只是一个虾纸丫 提交于 2019-12-10 09:37:23
问题 I'm reading in csv-files with in one column a string that should be converted to a datetime. The string is in the form MM/dd/yyyy HH:mm . However when I try to transform this using joda-time, I always get the error: Exception in thread "main" java.lang.UnsupportedOperationException: Schema for type org.joda.time.DateTime is not supported I don't know what exactly the problem is... val input = c.textFile("C:\\Users\\AAPL.csv").map(_.split(",")).map{p => val formatter: DateTimeFormatter =