jodatime

Joda DateTime to Unix DateTime

牧云@^-^@ 提交于 2019-12-12 07:24:44
问题 It's odd enough, but I didn't find any result about converting Joda(Time) DateTime to Unix DateTime (or timestamp, whichever is the correct name). How can I do this? 回答1: Any object that inherits from BaseDateTime (including DateTime ) has the method public long getMillis() According to the API it: Gets the milliseconds of the datetime instant from the Java epoch of 1970-01-01T00:00:00Z. So a working example to get the seconds would simply be: new DateTime().getMillis() / 1000 For

Getting the exact years or days or months between two joda date [duplicate]

岁酱吖の 提交于 2019-12-12 06:02:29
问题 This question already has answers here : Java method to find difference between 2 date objects in years, months and days (7 answers) Closed 2 years ago . I need to get the exact difference in terms of days and months and years between two joda date time. I am using the code below: DateTime jodaStartTime=new DateTime(startTime); DateTime jodaEndTime=new DateTime(endTime); Period period = new Period(jodaStartTime, jodaEndTime); System.out.print(period.getYears() + " years, "); System.out.print

Joda-Time Hibernate PersistentYearMonthDay Deprecated

北战南征 提交于 2019-12-12 05:30:05
问题 In looking through the Joda-Time Hibernate user guide it appears that there is no future support for the SQL DATE type. Since TIMESTAMP is specified to start on Jan 1, 1970 - the only safe transport for dates before 1970 appears to be VARCHAR with PersistentLocalTimeAsString (if one wishes to restrict themselves to the Joda Hibernate library). As someone who uses DATE (and seeing that Joda Hibernate isn't) I am wondering if there is some reason I should switch to VARCHAR and

Joda Time - inconsistent result

流过昼夜 提交于 2019-12-12 04:58:28
问题 I ran a quick test on daysBetween function in Joda-Time library and I am getting inconsistent result. Does anyone else have the same problem? Below is the code I use for testing. public static int elapsedDaysJoda() { DateTime dt1 = new DateTime(new Date()); Calendar cal = Calendar.getInstance(); cal.set(2011, 0, 1); DateTime dt2 = new DateTime(cal.getTime()); Days days = Days.daysBetween(dt2, dt1); return days.getDays(); } public static void main(String[] args) { for(int i=0; i < 10; i++) {

In a JSP scriptlet, how do you access a java.util.Date value passed from a Spring MVC ModelMap?

时间秒杀一切 提交于 2019-12-12 04:28:42
问题 FooController.java: @RequestMapping(value = "/foo", method = RequestMethod.GET) public final String foo(HttpServletRequest request, ModelMap model) { java.util.Date myDate = new java.util.Date(); model.addAttribute("myDate", myDate); return "foo"; } foo.jsp: <% java.util.Date myUtilDate = (java.util.Date)request.getParameter("myDate"); org.joda.time.DateTime myJodaDate = new org.joda.time.DateTime(myUtilDate); %> <joda:format value="${myJodaDate}" style="LL"/> Why does the JSP scriptlet fail

Time series data not being interpreted properly

时光毁灭记忆、已成空白 提交于 2019-12-12 04:12:38
问题 I'm trying to create a simple line chart using a time series. The problem is that androidplot is not properly displaying the time values from the array, i.e. the dates are off. The dates should be: Jan 1 2001, Feb 1 2001, Mar 1 2001, Apr 1 2001, May 1 2001 but I am getting: Jan 1 2001, Jan 30 2001, Mar 1 2001, Mar 31 2001, May 1 2001 You can see from the the debug info in the formatted what data androidplot has interpreted. I am using JodaTime for time. Code is here: public class

Equivalent of joda LocalTime getMillisOfDay() in noda

不问归期 提交于 2019-12-12 03:41:33
问题 I am porting some code from Java to .NET and looking for a noda-time equivalent of the getMillisOfDay() joda-time method of the LocalTime object. Is there an equivalent one or must I code my own? 回答1: In Noda Time 1.x, use the LocalTime.TickOfDay property, and then just divide it by NodaConstants.TicksPerMillisecond to get milliseconds: LocalTime localTime = ...; long millis = localTime.TickOfDay / NodaConstants.TicksPerMillisecond; 回答2: Closest you can get to the number of milliseconds since

Joda Time - Convert UTC DateTime to Date - Using a Version 1.2.1.1 of Joda

自古美人都是妖i 提交于 2019-12-12 03:23:49
问题 Good morning everyone. I'd like to help you to see how I can accomplish the conversion of a org.joda.time.DateTime to java.util.Date using the 1.2.1.1 version of Joda Time. Why Joda 1.2.1.1 ? Because currently I can only work with this version of Joda "unfortunately". My Test> System.out.println("JODA Version : 2.8.2 - UTC TIME to Date " + new DateTime().withZone(DateTimeZone.UTC).toLocalDateTime().toDate());; System.out.println("JODA Version : 1.2.1.1 - UTC TIME to Date " + new DateTime()

Java (Joda): Seconds from midnight of LocalDateTime

自闭症网瘾萝莉.ら 提交于 2019-12-12 02:52:40
问题 I tried to use this: secondsFromMidnight = Seconds.secondsBetween(localDateTime.toLocalDate(), localDateTime).getSeconds(); but it throws an exception (cf. below). I think this is a good approach, but I did not succeed in adapt it to my case yet. If I write this: DateTime dateTimeFromMidnight = new DateMidnight(localDateTime.getChronology()).toDateTime(); Duration duration = new Duration(dateTimeFromMidnight, localDateTime.toDateTime()); it messes up with time zones (I get 1 hour less). If

appengine datastore change entities property

白昼怎懂夜的黑 提交于 2019-12-12 02:32:04
问题 I would like to change the entity property from String to long. I have seen Nick answering similar problem in Change IntegerProperty to FloatProperty of existing AppEngine DataStore but I am writing in Java and need some code example since I don't know anything about the mapreduce. e.g. we want to change userId from String to Long of this class. I also would like to get advice on my thinking of storing date in long instead of String so that the time information can be consumed readily from