Skip to content
Advertisement

Tag: date

How to calculate “time ago” in Java?

In Ruby on Rails, there is a feature that allows you to take any Date and print out how “long ago” it was. For example: Is there an easy way to do this in Java? Answer Take a look at the PrettyTime library. It’s quite simple to use: You can also pass in a locale for internationalized messages: As noted

Recognise an arbitrary date string [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations. Closed 1 year ago. Improve this question I need to be able to recognise date strings. It doesn’t

Holidays – is there a java implementation?

I’d like to know if there is a jar-file out there that could do the following: If there isn’t, why? Surely there are lots of properly based rules for the holidays in 99% of the times. Right now we’re mainting a table in our database, with the countries + we have some implementation when it comes to holidays that aren’t

java.util.Date to XMLGregorianCalendar

Isn’t there a convenient way of getting from a java.util.Date to a XMLGregorianCalendar? Answer I should like to take a step back and a modern look at this 10 years old question. The classes mentioned, Date and XMLGregorianCalendar, are old now. I challenge the use of them and offer alternatives. Date was always poorly designed and is more than 20

How to convert java.util.Date to java.sql.Date?

I am trying to use a java.util.Date as input and then creating a query with it – so I need a java.sql.Date. I was surprised to find that it couldn’t do the conversion implicitly or explicitly – but I don’t even know how I would do this, as the Java API is still fairly new to me. Answer tl;dr How

How to sanity check a date in Java

I find it curious that the most obvious way to create Date objects in Java has been deprecated and appears to have been “substituted” with a not so obvious to use lenient calendar. How do you check that a date, given as a combination of day, month, and year, is a valid date? For instance, 2008-02-31 (as in yyyy-mm-dd) would

How to convert a date String to a Date or Calendar object?

I have a String representation of a date that I need to create a Date or Calendar object from. I’ve looked through Date and Calendar APIs but haven’t found anything that can do this other than creating my own ugly parse method. I know there must be a way, does anyone know of a solution? Answer In brief: See SimpleDateFormat

Advertisement