jodatime

Android force close with JodaTime

隐身守侯 提交于 2019-12-06 11:03:38
Has anybody used jodatime with android? I'm getting a force close with no trace. package test.journal.help; import java.util.Date; import org.joda.time.DateTime; import org.joda.time.Days; import android.app.Activity; import android.os.Bundle; public class journaltester extends Activity { /** Called when the activity is first created. */ private Date today = new Date(); public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Days days = Days.daysBetween(new DateTime(today), new DateTime(today)); setContentView(R.layout.main); } } Value of today : "Sat Aug 07 00:00

Current datetime in Joda-Time date formatting for mysql timestamp

ⅰ亾dé卋堺 提交于 2019-12-06 10:29:25
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 string argument and not a DateTime argument: public void setCreated(){ DateTime now = new org.joda.time

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

青春壹個敷衍的年華 提交于 2019-12-06 10:08:11
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" is malformed at "T23:00:00.000Z" Is there a way how to force Joda-Time to ignore rest of the string?

Grails controller unit tests with Joda Time

北城以北 提交于 2019-12-06 09:32:12
Some of the controller tests that generate-all creates are failing when I have a domain object with a Joda LocalDateTime field. $ grails create-app bugdemo $ cd bugdemo $ grails create-domain-class Item Edit grails-app/domain/bugdemo/Item.groovy package bugdemo import org.joda.time.LocalDateTime class Item { String name // LocalDateTime opening static constraints = { name blank:false } } Add the following line to BuildConfig.groovy compile ":joda-time:1.4" Continue at the command line $ grails compile $ grails install-joda-time-templates $ grails generate-all bugdemo.Item $ grails test-app

Convert Joda-Time `DateTime` with timezone to DateTime without timezone?

試著忘記壹切 提交于 2019-12-06 08:51:09
Given a DateTime for example 2015-07-09T05:10:00+02:00 using Joda-Time ? How can I convert it to local time, meaning adding the timezone to the time itself. Desired output: 2015-07-09T07:10:00 I tried dateTime.toDateTime(DateTimeZone.UTC) but that did not give the desired result. What @Nazgul said is right, but in case all you want to achieve is a "wall-time" in UTC zone you can do something like that: DateTime dateTimePlus2 = DateTime.parse("2015-07-09T05:10:00+02:00"); System.out.println(dateTimePlus2); DateTime dateTimeUTC = dateTimePlus2.withZone(DateTimeZone.UTC); System.out.println

Get Date of the first day in the first week of a year in Joda Time

元气小坏坏 提交于 2019-12-06 08:44:44
问题 I have a Java date: tempDate = Sun Jan 01 00:00:00 GMT+01:00 2012. I would like to create a new Date, that is the first day of the first week in the year of tempDate. That is: Mon Jan 02 00:00:00 GMT+01:00 2012 When I try to use Joda Time: DateTime cal = new DateTime(tempDate).withWeekOfWeekyear(1). withDayOfWeek(DateTimeConstants.MONDAY); I get what I want, but in the previous year: Mon Jan 03 00:00:00 GMT+01:00 2011 How can I make this work in Joda Time? 回答1: You must understand the

Slick: Filtering all records which have a joda DateTime date equal to today

半世苍凉 提交于 2019-12-06 06:16:01
问题 One way to achieve it would be like this: val now = DateTime.now val today = now.toLocalDate val tomorrow = today.plusDays(1) val startOfToday = today.toDateTimeAtStartOfDay(now.getZone) val startOfTomorrow = tomorrow.toDateTimeAtStartOfDay(now.getZone) val todayLogItems = logItems.filter(logItem => logItem.MyDateTime >= startOfToday && logItem.MyDateTime < startOfTomorrow ).list Is there any way to write the query in a more concise way? Something on the lines of: logItems.filter(_.MyDateTime

JodaTime LocalDate/LocalTime not Parsing with custom JSON Serializer classes

两盒软妹~` 提交于 2019-12-06 06:15:18
I have an object called ReportEvent which takes in a LocalTime as well as a LocalDate from the JodaTime API/framework. This ReportEvent is able to be written to JSON via google's GSON conversion API. However when deserializing the JodaTime partial causes problems. Logcat Error Report: 10-16 13:23:01.812: E/AndroidRuntime(8884): FATAL EXCEPTION: main 10-16 13:23:01.812: E/AndroidRuntime(8884): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nanospark.cnc/com.nanospark.cnc.MainActivity}: java.lang.IllegalArgumentException: Invalid format: "{"iChronology":{"iBase":{"iMinDa.

Convert seconds to years/days/hours/minutes automatically, using JodaTime?

放肆的年华 提交于 2019-12-06 06:13:49
Is there way to convert 'x' seconds to y hours and z seconds when say x exceeds 3600 seconds? Similarly, convert it to 'a minutes and b seconds' when x exceeds 60 but is less than 3600 seconds, using JodaTime? I understand that I would have to specify what I need in the PeriodFormatter, but I don't want to specify it - I want a formatted text based on value of seconds. This is similar to how you would post on a forum and then your post will initially be shown as 'posted 10 seconds ago'.. after 1 minute you would see 'posted 1minute 20 seconds ago' and likewise for weeks,days,years. I'm not

NPE in spark with Joda DateTime

独自空忆成欢 提交于 2019-12-06 05:13:55
When executing simple mapping in spark on joda DateTime field I am receving NullPointerException. Code snippet: val me1 = (accountId, DateTime.now()) val me2 = (accountId, DateTime.now()) val me3 = (accountId, DateTime.now()) val rdd = spark.parallelize(List(me1, me2, me3)) val result = rdd.map{case (a,d) => (a,d.dayOfMonth().roundFloorCopy())}.collect.toList Stacktrace: java.lang.NullPointerException at org.joda.time.DateTime$Property.roundFloorCopy(DateTime.java:2280) at x.y.z.jobs.info.AggJobTest$$anonfun$1$$anonfun$2.apply(AggJobTest.scala:47) at x.y.z.jobs.info.AggJobTest$$anonfun$1$