Skip to content

Tag: date

How to get the weekday of a Date?

I want to get the day of week from the Java Date object when I have an array of Date in String with me. Does anyone know the answer to this? Answer You can get the day-integer like that: If you need the output to be “Tue” rather than 3, instead of going through a calendar, just reformat the string…

How to convert “Mon Jun 18 00:00:00 IST 2012” to 18/06/2012?

I have a value like the following Mon Jun 18 00:00:00 IST 2012 and I want to convert this to 18/06/2012 How to convert this? I tried this method but it throws following exception : java.text.ParseException: Unparseable date: “Mon Jun 18 00:00:00 IST 2012” Answer I hope following program will solve…

how to store date AND time with JPA in Oracle?

I’m using WebSphere 7 (Java EE 5) and OpenJPA 1.2.1. I have a JPA object with a “modifiedTimestamp” attribute, something like this: The related field in the Oracle database is of type DATE. I set the date like so … … and it gets stored, but when I read it back the time of day has…

Loop through Months in Java / Android

I want to loop through months of the year and print out. for example: 01/2012 02/2012 03/2012 04/2012 etc… Here is my code: It is printing out in int’s 1 2 3 4 5 However, when I convert it to a date string, as seen in code above, it does this: 05/2012 06/2012 08/2012 11/2012 03/2013 08/2013 Basica…

Date formatting according to country habbits

We create J2SE application that has to format the date and time according to custom the country from which users come from. I want to ask how to solve this thing in Java? Probably I’ll use SimpleDateFormat, but I wonder if it is possible to get format string in somehow simpler way than to have all forma…