jodatime

How to convert from java.util.date to JodaTime and get same date

一个人想着一个人 提交于 2019-12-06 03:05:49
问题 I follow this question: Convert from java.util.date to JodaTime I have date: Sun Jan 01 00:00:00 CET 1854 now I want to convert it to joda datetime: DateTime dateTime = new DateTime(date); and now when I print this date I got: 1853-12-31T23:57:44.000+00:57:44 what is wrong and why my date changed ? How I can get the same date ? UPDATE: I get date using calendar: Calendar cal1 = Calendar.getInstance(); cal1.set(1854, 0, 1, 0, 0, 0); cal1.getTime() UPDATE2: propably there is problem with

UserType / Hibernate / JodaTime - where to set UserType global properties?

徘徊边缘 提交于 2019-12-06 02:47:41
问题 I'm using the org.jadira.usertype.dateandtime.joda.PersistentDateTime class from UserType 3.0.0.RC1 to map a JodaTime DateTime to Hibernate. The Javadocs for the class mention that there are 'databaseZone' and 'jvmZone' properties which I would like to set, but I cannot find anything in the UserType documentation that indicates how to do this. I found this thread which seems to imply that these are set by XML similar to the following: <prop key="jadira.usertype.autoRegisterUserTypes">true<

MySQL DATETIME precision (joda-time, Hibernate, org.jadira.usertype, hbm2ddl)

萝らか妹 提交于 2019-12-06 02:31:22
问题 In my hibernate-4 entity, I am mapping a joda-time DateTime property using the recommended jadira usertypes: @Entity @Table(name="timing") public class TimingEntity { ... @Basic(optional=false) @Column(name="moment") @Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime") public DateTime getMoment() { ... My database is MySQL. With hibernate property hbm2ddl.auto set to create value, I have the following column generated in my timing table: CREATE TABLE `timing` ( ... `moment`

Set default/global date format in Spring MVC to ISO 8601

爷,独闯天下 提交于 2019-12-06 01:49:31
问题 I have a simple Spring Controller: @RequestMapping(value="", method=RequestMethod.GET) public void search(MyDTO dto) { // ... } And MyDTO : public class MyDTO { private DateTime date; public DateTime getDate() { return date; } public void setDate(DateTime date) { this.date = date; } } I actually can call the controller method with my local date format: 03.10.2013 01:00 , e.g. GET http://localhost:8080/test?date=03.10.2013 01:00 But I want application wide ISO 8601 date format, e.g.: 2007-03

getting DateTime from ResultSet in JdbcTemplate

时光怂恿深爱的人放手 提交于 2019-12-06 01:26:59
问题 in database my column is of type TIMESTAMP, so my class has properties of type Datetime like this: public void setDiscoveryDate(final DateTime discoveryDtTm) { this.discoveryDtTm = discoveryDtTm; } now in JdbcTemplate I want to get it, so some code like this: variant.setDiscoveryDate(rs.getTimestamp("discovery_dt_tm")); which does Not work because column the get for resultset I could not find something that returns DateTime, I only saw either getDate or getTime. 回答1: That's because DateTime

Generate Date ranges in JodaTime

江枫思渺然 提交于 2019-12-06 00:00:34
问题 I need to check if a date(in string) exists in array list. I have two dates, first i need to generate date ranges between these two dates and store them in an Array. This is what I am doing. DateTimeFormatter dateFromatter= DateTimeFormat.forPattern("MM/dd/yyyy"); DateTime startDate= formatter.parseDateTime("01/02/2012"); DateTime endDate= formatter.parseDateTime("01/31/2012"); List<LocalDate> dates = new ArrayList<LocalDate>(); int days = Days.daysBetween(startDate, endDate).getDays(); for

Joda-Time - How to find “Second Thursday of Month”

蓝咒 提交于 2019-12-05 23:31:39
I'm not seeing a good way to set a date to a certain day of the week for a certain week of the month. Joda-Time 's LocalDate does not have a withWeekOfMonth method. I can see a possible algorithm, but it seems way to complicated, so I'm going to assume I'm missing something. What I need is to determine the next date someone is paid. And if they are paid on the Second Thursday of the Month, what date is that. Anyone already solved this problem? Ok, I was able to come up with this, which seems to work fine. /** * Finds a date such as 2nd Tuesday of a month. */ public static LocalDate

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

让人想犯罪 __ 提交于 2019-12-05 19:37:47
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 = DateTimeFormat.forPattern("MM/dd/yyyy HH:mm"); val date: DateTime = formatter.parseDateTime(p(0)); StockData

convert epoch to datetime in Scala / Spark

与世无争的帅哥 提交于 2019-12-05 18:52:13
I'm converting String representing a DateTime to unix_time (epoch) using : def strToTime(x: String):Long = { DateTimeFormat. forPattern("YYYY-MM-dd HH:mm:ss").parseDateTime(x).getMillis()/1000 } to get a list of Long like this : .map( p=> List( strToTime(p(0) ) ) ) my question is - what is the easiest way to turn in backwards? something like: def timeToStr(x: Long):String = { x*1000L.toDateTime} that I could use on the above List(Long) I have read Convert seconds since epoch to joda DateTime in Scala but can't apply it successfully You have a precedence problem - .toDateTime is being applied

Jodatime date format

久未见 提交于 2019-12-05 17:10:54
Is it possible to format JodaTime Date. Here is the code: private static LocalDate priorDay(LocalDate date1) { do { date1 = date1.plusDays(-1); } while (date1.getDayOfWeek() == DateTimeConstants.SUNDAY || date1.getDayOfWeek() == DateTimeConstants.SATURDAY); //System.out.print(date1); return date1; } Here date1 returns as: 2013-07-02 but i would like as 02-JUL-13 Thanks in advance Is it possible to format JodaTime Date Yes. You want DateTimeFormatter . DateTimeFormatter formatter = DateTimeFormat.forPattern("dd-MMM-yy") .withLocale(Locale.US); // Make sure we use English month names String text