jodatime

Convert joda.time.DateTime to java.sql.Date and retain time zone

最后都变了- 提交于 2020-01-12 05:50:30
问题 I have the following scenario: Swing control that returns a Calendar object Intermediate DateTime object that I use to do heavy date/time manipulation (joda) Database connection ( OraclePreparedStatement ) that only takes a java.sql.Date object My problem is that the Calendar and DateTime objects are properly displaying the date in GMT (which I want), but when I convert to java.sql.Date in order to send to the database, the date is converted to the local time zone. For example: Calendar and

Joda Time: Convert UTC to local

折月煮酒 提交于 2020-01-12 05:35:08
问题 I want to convert a Joda Time UTC DateTime object to local time. Here's a laborious way to do it which seems to work. But there must be a better way. Here's the code (in Scala) without surrounding declarations: val dtUTC = new DateTime("2010-10-28T04:00") println("dtUTC = " + dtUTC) val dtLocal = timestampLocal(dtUTC) println("local = " + dtLocal) def timestampLocal(dtUTC: DateTime): String = { // This is a laborious way to convert from UTC to local. There must be a better way. val instantUTC

How to get list of dates from some date? [duplicate]

跟風遠走 提交于 2020-01-11 11:54:05
问题 This question already has answers here : how to get a list of dates between two dates in java (22 answers) Closed 2 years ago . I have two variables: startDate - for example 29/04/2018 howManyDays - for example 30 I want to get list of 30 days from date 29/04/2018. Can you tell me how can I do it? I found only days beetwen two dates. int days = Days.daysBetween(startDate, endDate).getDays(); List<LocalDate> dates = new ArrayList<LocalDate>(days); // Set initial capacity to `days`. for (int i

Serializing custom object that contains JodaTime objects into JSON

情到浓时终转凉″ 提交于 2020-01-10 19:37:15
问题 After running a second activity that creates an object and stores it into an ArrayList inside of a Singleton I get this error when returning to the first Activity from the creation Activity . Logcat: 10-09 15:00:48.125: E/AndroidRuntime(4266): FATAL EXCEPTION: main 10-09 15:00:48.125: E/AndroidRuntime(4266): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nanospark.cnc/com.nanospark.cnc.ContactCreateActivity}: java.lang.RuntimeException: Failed to invoke public org.joda

Understanding the Etc/GMT time zone

主宰稳场 提交于 2020-01-09 03:43:48
问题 What is the rationale behind Apple using Etc/GMT timezone when they return the receipt from the App Store for auto-renewable subscriptions. What exactly is the Etc/GMT time zone? Does the Java SDK understand this time zone? Or do I have to use other third-party libraries like Joda-Time? 回答1: Etc/GMT is not strictly the same thing as UTC or GMT. They represent the same instant in time only when the offset is 0. In all other cases, they are quite different. Apple explains the designation here.

convert string timestamp to ISO 8601 compliant string

我们两清 提交于 2020-01-07 05:31:04
问题 I have a timestamp and offset in string format as shown below in two different variables: 01/14/2016 07:37:36PM -08:00 I want to convert above timestamp into ISO 8601 compliant String, with milliseconds and timezone so it should look like this after conversion: 2016-01-14T19:37:36-08:00 How can I do that? I am using jodatime library. 回答1: The newer java.time classes work so well with ISO 8601 strings. String dateTimeString = "01/14/2016 07:37:36PM"; String offsetString = "-08:00";

converting UTC date string to local date string inspecific format

陌路散爱 提交于 2020-01-07 00:36:13
问题 I have a UTC date in string String utcDate = "2014-03-05 07:09:07.0"; I want to convert it to local date string of format DD-MMM-YYYY hh:mm a eg: 5-Mar-2014 12:39 PM from UTC date 2014-03-05 07:09:07.0 How this can be achieved using simple java or joda API 回答1: Very easy to achieve with default functionality. I hope the local data is for display only. SimpleDateFormat parser = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); parser.setTimeZone(TimeZone.getTimeZone("UTC")); Date parsed = parser

Persist a list of LocalDate with GORM

扶醉桌前 提交于 2020-01-06 16:19:22
问题 I'm trying to persist a list of joda LocalDate in grails. What I have right now is something like this: package com.publidirecta import org.joda.time.LocalDate class Evento { List <LocalDate> fechas = [] static hasMany = [fechas:LocalDate] } and I get the following error : MappingException: Missing type or column for column[fechas_persistent_local_date] on domain[Evento] referencing[org.jadira.usertype.dateandtime.joda.PersistentLocalDate] ->> 334 | innerRun in java.util.concurrent.FutureTask

Persist a list of LocalDate with GORM

為{幸葍}努か 提交于 2020-01-06 16:19:01
问题 I'm trying to persist a list of joda LocalDate in grails. What I have right now is something like this: package com.publidirecta import org.joda.time.LocalDate class Evento { List <LocalDate> fechas = [] static hasMany = [fechas:LocalDate] } and I get the following error : MappingException: Missing type or column for column[fechas_persistent_local_date] on domain[Evento] referencing[org.jadira.usertype.dateandtime.joda.PersistentLocalDate] ->> 334 | innerRun in java.util.concurrent.FutureTask

Calculate days between today and string of format yyyy/mm/dd in Java [duplicate]

久未见 提交于 2020-01-05 12:13:43
问题 This question already has answers here : Calculating the difference between two Java date instances (45 answers) How do you subtract Dates in Java? [duplicate] (5 answers) Closed 5 years ago . I have a String representing a date with format yyyy/mm/dd and want to calculate the number of days between that day and today. How is this done? So It may be something like String aDate = "1934/05/24" 回答1: Way to do this - Parse the date string to Date object using SimpleDateFormat . Get the date