jodatime

String to LocalDate

瘦欲@ 提交于 2019-12-17 04:52:15
问题 How can i convert a string to a LocalDate ? I have seen examples like: LocalDate dt = new LocalDate("2005-11-12"); But my strings are like: 2005-nov-12 回答1: As you use Joda Time, you should use DateTimeFormatter : final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MMM-dd"); final LocalDate dt = dtf.parseLocalDate(yourinput); If using Java 8 or later, then refer to hertzi's answer 回答2: java.time Since Java 1.8, you can achieve this without an extra library by using the java.time

How to calculate elapsed time from now with Joda-Time?

拥有回忆 提交于 2019-12-16 22:39:15
问题 I need to calculate the time elapsed from one specific date till now and display it with the same format as StackOverflow questions, i.e.: 15s ago 2min ago 2hours ago 2days ago 25th Dec 08 Do you know how to achieve it with the Java Joda-Time library ? Is there a helper method out there that already implements it, or should I write the algorithm myself? 回答1: To calculate the elapsed time with JodaTime, use Period. To format the elapsed time in the desired human representation, use

How to find difference between two Joda-Time DateTimes in minutes

こ雲淡風輕ζ 提交于 2019-12-16 22:09:26
问题 Below is the method I wrote: public List<Map<String, Object>> loadNotYetInEmployee(int shift, Date date, int transitionVal, String type, User user) { DateTime datetime = new DateTime(date); datetime = datetime .plus(Period.minutes(shiftTiming.getSession1InTime())); List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(); sql = SqlMapUtils.getSql("attendance.attendancestatus.latein", parameters); result = getJdbcTemplate().queryForList(sql); for (int i = 0; i < result.size(); i

how to get a timestamp of another timezone in java or JODA

左心房为你撑大大i 提交于 2019-12-13 22:13:42
问题 i want to get current time (now) from Different time zone . for example using joda datetime library, I can get Australian time zone like using JODA datetime DateTime zoned = new DateTime(DateTimeZone.forID("Australia/Melbourne")); and its current time Using DateTime.now(DateTimeZone.forID("Australia/Melbourne")); if i want to convert this DateTime object into java.sql.Timestamp object ,i have to get its milliseconds using getMillis method of DateTime class to instantaite new Timestamp Object

Java EE: NoClassDefFoundError org.joda.time.DateTime with IntelliJ and Maven

丶灬走出姿态 提交于 2019-12-13 18:29:57
问题 I am using IntelliJ 14 I want to add joda.time lib in my project. When I add this lib manually (copy the jar file into lib repository, and add reference in Project Structure) everything work good, I can use the library in a servlet and show the result in a jsp. But in second step I create the same project but I am using maven with a pom.xml file. I add this dependency : <dependencies> <dependency> <groupId>joda-time</groupId> <artifactId>joda-time</artifactId> <version>2.1</version> <

Persisting time ojects as entities instead of value types?

烈酒焚心 提交于 2019-12-13 17:14:50
问题 I'm using Joda Time DateTime to handle date and time. I persist objects of this kind using the class PersistentDateTime bundled in the jodatime hibernate code. I have large collections of DateTime objects, and I currently persist them in the following way (an excerpt of an hibernate mapping file follows): <set name="validInstants" sort="natural"> <key column="myobject_id"/> <element column="date" type="myproject.utilities.hibernate.types.PersistentDateTime"/> </set> Doing so, i.e. storing

converting string representation of unknown date-format to Date in java

会有一股神秘感。 提交于 2019-12-13 16:15:26
问题 I have a string that represents a date. I do not know the date format of the string. But for example only, it may be any of 2015-10-14T16:41:42.000Z 2015-10-14T19:01:53.100+01:00 2015-10-14 05:20:29 or any valid format that a website may use to describe date in a meta tag (so the format will be official, as opposed to whimsical, but the set of possibilities is not small). Can I use joda-time to solve this issue? How about java.util.Date or anything else? update I think I find a Javascript

Using Joda-Time to form correct ISODate for Mongo insert

末鹿安然 提交于 2019-12-13 12:06:37
问题 I am trying to update date fields in mongo that require an ISODate format. In mongo, it looks like this: "crDt" : ISODate("2013-08-19T17:21:57.549Z") The Java framework I am using has me restricted to using strings as my test parameters, so I am trying to use that string with a DateTimeFormatter to get it into the correct ISODateTimeFormat and then pass that into mongo. I cannot just pass in a string that looks like what I have above. Trying to do so screws up the field in mongo. The relevant

How to convert ( round ) epoch Time to nearest hour and day wrt IST (in Java)

非 Y 不嫁゛ 提交于 2019-12-13 06:01:29
问题 I have time in epoch format (as Java long variable). I want to convert it to nearest hour as well as day with respect to Indian Standard Time (IST). For example, if the epoch time is 1372618032000 (7/1/2013 12:17:12 AM IST), then i want to get 1372620600000 (7/1/2013 1:00:00 AM IST). Similarly for day rounding. I want to get 1372703400 (7/2/2013 12:00:00 AM IST). [Starting of the next day.] I have gone through some documentation of Java Date, Java Calendar, Apache DateUtils, and JodaTime. But

Storing a “fake” timestamp into a database

北慕城南 提交于 2019-12-13 05:54:15
问题 Here is the problem I am trying to solve: Read a string from database A, convert the string into a Date object, store the Date object into database B. EX) Database A: Read in date string "2015-03-08 02:00:00" from database A, convert into a Date object, store back into database B. The problem here occurs because 2:00 AM is the beginning of DST in U.S. Central time, so the Data object converts 2:00 AM straight into 3:00 AM, which means 3:00 AM gets stored into database B . Is there any way to