jodatime

Joda time zone different than JDK's

点点圈 提交于 2019-12-18 07:04:11
问题 In my client, I have this code: System.out.println("Java tz: " + TimeZone.getDefault()); System.out.println("Joda tz: " + ISOChronology.getInstance()); These two lines run one after another. I never set time zone or user.timezone manually, just rely on defaults read from the OS & local system. When executed, they produce: Java tz: sun.util.calendar.ZoneInfo[id="UTC",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null] Joda tz: ISOChronology[America/Phoenix] System time zone is

Calculating end date while skipping holidays + Joda time

蓝咒 提交于 2019-12-18 06:17:24
问题 I would like to calculate end date (and time) of an event. I know starting date and duration (in minutes). But: I have to skip holidays - non-recurrent situation I have to skip weekends - recurrent situation I have to not count working time (e.g: from 8:00am till 5:00pm) - recurrent situation, but with finer granularity Is there a simple way to achieve these cases using Joda time library? 回答1: Jodatime will help you -a lot I'd say-, but you'll need to write the logic yourself, a loop skipping

Calculating end date while skipping holidays + Joda time

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-18 06:17:06
问题 I would like to calculate end date (and time) of an event. I know starting date and duration (in minutes). But: I have to skip holidays - non-recurrent situation I have to skip weekends - recurrent situation I have to not count working time (e.g: from 8:00am till 5:00pm) - recurrent situation, but with finer granularity Is there a simple way to achieve these cases using Joda time library? 回答1: Jodatime will help you -a lot I'd say-, but you'll need to write the logic yourself, a loop skipping

jodatime how to know if daylight savings is on

不羁岁月 提交于 2019-12-18 05:44:21
问题 I have an API that needs the timezone. For eg. if I am in california, I need to pass -7 to it when daylight savings is on (California , PDT is GMT - 7) and -8 to it when daylight saving is off. But I am not able to figure out a way of knowing whether on the current date, daylight saving is on or off. Date date1 = new Date(); Calendar cal = Calendar.getInstance(); cal.setTime(date1); double[] coords = db.getCoords(id1); double latitude = coords[0]; double longitude = coords[1]; double timezone

How to calculate difference ONLY in months using Java's Joda API

自作多情 提交于 2019-12-18 04:46:05
问题 I am writing a program that is supposed to just calculate the months between 2 given dates and return the value to the program. For instance, if I have to calculate the number of months between 1 April and 30 June (which is a quarter, 3 months), and I use the following code: DateTime start = new DateTime().withDate(2011, 4, 1); DateTime end = new DateTime().withDate(2011, 6, 30); Months mt = Months.monthsBetween(start, end); int monthDiff = mt.getMonths(); Using this, I am still getting "2"

Hibernate TypeResolver

心已入冬 提交于 2019-12-18 04:34:07
问题 I'm aware that hibernate recently redid its type system in 3.6. I think this now allows you do associate a java Class with a Type (or UserType). For example I use joda-time and have a couple of UserTypes that map the LocalDate and LocalDateTime into appropriate SQL types. This works fine when working with objects but if I want to pass a joda type as a HQL parameter hibernate gets confused so I have to remember to supply the Type each time I make a call. query.setParameter( "now", new

Java Joda Time - download, and install - step by step [closed]

人盡茶涼 提交于 2019-12-17 23:10:22
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I've had trouble getting Joda Time to install and work. Most of the instructions around assume a certain amount of knowledge. Can someone please assume I know nothing and guide me through, step by step, where to

Persist Joda-time's DateTime via Hibernate

喜夏-厌秋 提交于 2019-12-17 22:21:35
问题 I'm using Jodatime in my Play app, but currently having to do a bunch of converting back and forth from/to java.util.Date and java.sql.Time . Since jodatime is included in the Play distribution, I'm thinking there's probably a better way to do this. Is there any way I can make my Model fields DateTime s instead of java.util.Date and java.sql.Time so the conversion is done automatically? Is there another way of streamlining this? 回答1: For Hibernate 3 add the following annotation to your date

Convert date time string like Joda DateTime(String) with Java 8

柔情痞子 提交于 2019-12-17 21:37:06
问题 I have an API that can return date values in JSON in three possible formats: 2017-04-30T00:00+02:00 2016-12-05T04:00 2016-12-05 I need to convert all three into a java.time.LocalTimeDate . Joda has a nice constructor on the DateTime object which takes in all three formats as Strings and converts them. DateTime dt = new DateTime(StringFromAPI); is enough. Is there a similar capability in Java 8 ( java.time package)? It seems I now first have to regex the String to check the format, then create

How to use Joda DateTime with Play Json

你。 提交于 2019-12-17 19:15:06
问题 I'm developing a Play application, and I'm trying to use a Joda DateTime object into my case class. package model import org.joda.time.DateTime import play.api.libs.json._ case class User(name: String, created: DateTime) object User { implicit val yourJodaDateReads = Reads.jodaDateReads("yyyy-MM-dd'T'HH:mm:ss.SSSZ") implicit val yourJodaDateWrites = Writes.jodaDateWrites("yyyy-MM-dd'T'HH:mm:ss.SSSZ'") implicit val userFormat = Json.format[User] def main(args: Array[String]) { val value = Json