Format 1 « Date Time « Java Data Type Q&A

1. Formatting Timestamps in Java

Is there a way to format a UTC time into any arbitrary string format I want in java? Basically I was thinking of having some class take the timestamp and ...

2. Decimal DateTime formatter in Java or Joda

I'm writing a file that requires dates to be in decimal format:

2007-04-24T13:18:09 becomes 39196.554270833331000
Does anyone have a time formatter that will do this (Decimal time is what ...

3. Java date formatting?

I want to read a date in the format YYYY-MM-DD. But if I enter date say for example 2008-1-1, I want to read it as 2008-01-01. Can anybody help me? ...

4. Changing the date format

In Calc I set a cell value to "2006/10/03 13:33:55.448" and Calc says it is Standard format. I'm doing this with Java and I want to set the format to "DD.MM.YY ...

5. How can I calculate a time span in Java and format the output?

I want to take two times (in seconds since epoch) and show the difference between the two in formats like:

  • 2 minutes
  • 1 hour, 15 minutes
  • 3 hours, 9 minutes
  • 1 minute ...

6. Is there an easy way to Calculate and format time/date intervals in java?

I'm familiar with the the date and time classes in the JDK and their associated formatting methods. I may be blind, but I cannot find an equivalent set of classes for ...

7. String to Date in Different Format in Java

I want to convert String to Date in different Format. For example, I am getting from user,

String fromDate = "19/05/2009"; (dd/MM/yyyy);
I want to convert this fromDate as a Date object of "yyyy-MM-dd" ...

8. format years bc/ac differently

I would like to display e.g. 31-12-1999 for years ac and 31-12-(-)2000 for years bc. I spent some time with the joda api's e.g. something like:

new DateTimeFormatterBuilder().appendYear(4, 10).appendLiteral("-").appendMonthOfYear(2).appendLiteral("-").appendDayOfMonth(2).toFormatter();
but I cannot find any ...

9. Date Format - Java

I want to accept a Date format according to an ISO (can't remember which one)...

How do I do this? I'm currently using a SimpleDateFormat but when I run my unit test ...

10. How to get the current time in YYYY-MM-DD HH:MI:Sec.Millisecond format in Java?

The code below gives me the current time. But it does not tell anything about milliseconds.

public static String getCurrentTimeStamp() {
    SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//dd/MM/yyyy

11. jExcelApi - cell date format reusing doesn't work

I created a wrapper to jExcelApi classes to easily export lists of objects to Excel. To minimize object creation cell formats are created as static fields and reused in consecutive calls ...

12. How to convert a date String into the right format in Java?

Can somebody please explain to me how I can convert 2009-10-27 14:36:59.580250 into 27.10.2009, 14:36 ? The first date is available as a string and the second one should be a string as well ...

13. How can I customize Java Date Format

From the java doc, the MEDIUM format is: MEDIUM is longer, such as Jan 12, 1952 How can I customize it so that I does not display the year? And ...

14. Java date format real simple

how would you write te date if i have a date and all i want is the month and the day like this (mm/dd) and then turn the month like this ...

15. Formatting date 2/24 as "February, 24"

I am trying t make a date that comes in like this mm/dd turn into the name of the month and day like it comes in 8/15 i want it to ...

16. Java: unparseable date exception

While trying to transform the date format I get an exception:unparseable date and don't know how to fix this problem. I am receiving a string which represents an event date and ...

17. How to format dates in Jahia 6 CMS?

I am helping a friend of mine put up a site for his business. I’ve read different posts and sites trying to find the ideal CMS tool, but people have different ...

18. Custom date format cannot be parsed. (Java)

I have to parse a custom date format in Java. It contains microseconds although Java doesn't provide support for microseconds. Because of that I filled the format with zeroes, but now ...

19. Java Date issues

Im having a problem with java date's, when i pass a date before 1949 into the bellow method. The date i have returned is for example 2049, im aware it has somthing ...

20. Java Date exception handling try catch

Is there some sort of exception in Java to catch an invalid Date object? I'm trying to use it in the following method, but I don't know what type of exception ...

21. how to convert current date into string in java?

How do I convert the current date into string in java?

22. converting time from hh:mm:ss to hh:mm in java

I want to force the print screen of time like => hh:mm it comes from database (my sql) like hh:mm:ss. I tryed the following but i didn't got want i want.

 try {


23. Java simple date format british time

I am using simple date format to allow users to specify which time zone they are sending data in:

DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,z");
This works fine: e.g.
df.parse("2009-05-16 11:07:41,GMT");
However, if someone is always ...

24. How to format the date into words

I am trying to convert java.util.Date into string as "Twenty Sixth of October Nineteen Ninety Three" for the date 26-10-1993. How to do this in a generic fashion?

25. Parse non-standard date format like "+0yyyyMMdd"

I Have Date, that comes to our system in format +0yyyyMMdd For instance 12 March,2011 is +020110312 For now it's definitely + symbol and one 0 before Date, but in future it may ...

26. Date format in JAVA

I want to print April as APR IN JAVA WHERE 4 comes as parameter to indicate April. what can i do?i tried the format 'MMM' but it prints 'Apr' in ...

27. How to convert date format

Can any one help in conversion of date format? My returned date object is contains "Mon Jul 12 00:00:00 IST 2010" I'm trying to convert this date format to "MM/dd/yyyy" but I'm getting ...

28. date format parses the 12th hour value (hh) to 00

date format parses the 12th hour value (hh) to 00 while applying the format as "yyyy-MM-dd'T'hh:mm:ss" but it not parses the 13th hour to 1 PM. PFB the sample code piece. Date ...

29. how can i change the date format in java

i need to change the date format using java from

 dd/MM/yyyy  to yyyy/MM/dd

30. How to parse follow date in Java?

Hello i need to parse this string Sun, 15 Aug 2010 3:50 PM CEST I'm using SimpleDataFormat in this way

String date = "Sun, 15 Aug 2010 3:50 pm CEST";
DateFormat formatter = new SimpleDateFormat("EEE, ...

31. Java date/time format

How can I format: "2010-07-14 09:00:02" date to depict just 9:00?

32. Check date format before parsing

I am parsing several documments with the field Duration. But in the differents files, it is in differnt formats, ex:

"Duration": "00:43"  
"Duration": "113.046"  
"Duration": "21.55 s"
I want to parse ...

33. How to convert String to Date without knowing the format?

I have a problem. I am trying to convert some strings to date, and I don't know the format the date is arriving. It might come as hh:mm:ss or MM.dd.yy hh:mm:ss ...

34. Any easy ways to unformat a date?

I've got a bunch of dates in this String format:

String date = "Wed Sep 15 16:31:05 BST 2010";
and I'd like to convert it back to a date or calendar object. ...

35. Format date without year

How can create text representation of some date, that takes locale into account and contains only day and month (no year)? Following code gives me something like 23/09/2010

DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault()).format(date);
I want to get ...

36. how can i sort dd/mm/yy date format in datagrid using flex?

i used array collection sort method like below . but still sorting wrongly . Any other solution for sort date using flex3

public function SortingDate(ArrColl : ArrayCollection, field : ...

37. I have a date in(string) in dd-mon-yyyy format and I want to compare this date with system date

I have a date in(string) in dd-mon-yyyy format and I want to compare this date with system date. eg. I have 12-OCT-2010 and I want to compere this with system date in same ...

38. Can we create our own date format in Java?

I need to format a date(yyyyMMDD) into YYYY-MM-DD. Can I create a date format of the latter ?

39. Java Date Parse from one to another format

Is there a way whereby the date format can be determined in Java similar to .Net? Consider the following example:

private String reformatDateString(String dateParam){
    if(dateParam == null || dateParam.isEmpty()){

40. Java Format Detailed Difference Between Dates

I'm sure this has been asked before in some other way that I just can't find, so I apologize upfront for repeating if I am. I am trying to calculate the difference ...

41. parse this type of date format in java?

what would be the easiest way to parse this date format below in java?:

i read the DateFormat api in java and could not find a method that takes a string or ...

42. How to format a date String into desirable Date format

I was trying to format a string into date. For this I have written a code:-

Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
System.out.println(sdf.format( cal.getTime() ));
This is fine.. But now I want to convert ...

43. Showing period with days, hours, minutes and seconds

I have the following period 1month 5d 22h 35m 39s, which I want to format as 35d 22h 35m 39s. However when using the following formatter the months are just removed ...

44. date format in java

My requirement is to get the date in format MM/dd/yy. But I am currently getting the date value as "Sun Dec 31 00:00:00 IST 2006". I tried a sample code for ...

45. How to parse date string to Date?

How to parse the Date string below to Date object???

String target = "Thu Sep 28 20:29:30 JST 2000";
DateFormat df = new SimpleDateFormat("E MM dd kk:mm:ss z yyyy");
Date result =  df.parse(target); ...

46. Continous decreasing a time in java in format HH:MM:SS

I have a to implement a bidding system in a project and on the server, in the auction table, i have a field for start time and end time. What I am ...

47. Problem with Date Format in Java

I have a problem with this code

public static void main(String[] args) throws IOException, ParseException { 
    String strDate = "2011-01-12 07:50:00";
    DateFormat formatter ...

48. Parsing dates of the format "January 10th, 2010" in Java?

I need to parse the dates of the format "January 10th, 2010" in Java. How can I do this? Thanks in advance

49. OpenNLP is unable to identify dates of the format "January 10th, 2009"

OpenNLP(in Java) is unable to identify dates of the format "January 10th, 2010" or "January 10, 2010". I replaced all ','s in the text with an empty string "" before using ...

50. Format date in java

String date_s = "2011-01-18 00:00:00.0";
How do I convert a String object in Java to a date and output in date format YYYY-MM-DD (e.g. 2011-01-18)? Here's something I've tried:
String date_s = " 2011-01-18 ...

51. Format a date for use with text-to-speech in Java

I have a Date which I'd like to format into text that is usable by a text-to-speech engine. I am currently doing it by hand using various SimpleDateFormats. Examples of ...

52. What system default date format to use?

I'm setting the standards for our application. I've been wondering, what default date format should I choose to use ? It should be:

  • Internationalization & timezone aware, the format should be able to represent ...

53. java Date format

What date format is '2010-10-11T22:10:10.000Z' ?

54. Date Format Conversion in Java

I have a requirement in project to Convert 24 hours format to 12 hours format for example if it is 17:12:01 it should be converted to 05:12:01

55. Is there a date format to display the day of the week in java?

I know of date formats such as
"yyyy-mm-dd" -which displays date in format 2011-02-26
"yyyy-MMM-dd"-which displays date in format 2011-FEB-26 to be used in eg:

SimpleDateFormat formatter = new SimpleDateFormat(

56. Does DATE format affect the way dates are compared?

Say I've got two dates formatted this way:

date1 = Feb 22, 2011
date2 = Mon Feb 21 08:30:03 EST 2011 (default formatting)
will date2.compareTo(date1); still work? I've got a method I'm using to see ...

57. format date from 14 aug to YYYYMMDD

Change the date 14 aug 2011 to the format 20110814 .. how can i do that in java ? Here 14aug is a string ... String date="14aug";

58. Date format in java

      SimpleDateFormat sdf = new SimpleDateFormat("ddMMM", Locale.ENGLISH);

      try {


59. Faster way to create timestamp string in %.7f format

This is a function I have to create timestamp string in %.7f format. This function takes only 2-3 ms to execute. But its called from many places in my code, ...

60. Format a Date, allowing null

I'm trying to print a Date, just the way DateFormat.getDateTimeInstance() does it. format throws a NullPointerException when passing null, so I've been wondering if there is a different approach that ...

61. How to use joda time to format a fixed number of millisecons to hh:mm:ss?

I have input, 34600 milliseconds I would like to output this in the format 00:00:34 (HH:MM:SS). What classes should I look at JDK / Joda-time for this? I need this to be ...

62. Compare date Java format problem

Trying to compare some dates in java but can't get the formatting right, where am i going wrong?

DateFormat df = new SimpleDateFormat("dd/mm/yyyy");
    Date date1 = null, date2 = ...

63. How JAVA format date 4/06/2011 instead of 04/06/2011 use GregorianCalendar? String.format("%1$tm/%1$td/%1$tY", today);

How JAVA format date

instead of 0
? I need to use GregorianCalendar
GregorianCalendar today=new GregorianCalendar();
String todayStr = String.format("%1$tm/%1$td/%1$tY", today);
I want
thanks in advance ...

64. Converting string to a formatted date

I am trying to convert stringn to proper date format with format class of java..For some reason it's not working with certain months like MAr,May,Oct and Dec. Can somebody pl help ...

65. Formatting Date to get Date of a Specific format

I am trying to format Date to get a Date of a specific format. However it is not working. Don't know why! Here is what I did:


66. how to convert seconds_since_the_beginning_of_this_epoch to date format in java..?

how to convert seconds_since_the_beginning_of_this_epoch to date format in java..? for example i will have number(987777000) in ssboetod format i want it to be in normal date format Fri Apr 20 20:00:00 2001. ...

67. Formatting Of Timestamp

In my procedure I have formatted timestamp as follows Var_Abc varchar2 is output of the procedure

select to_char(max(datestamp),'DD-MON-YYYY hh24:mi:ss' 
into var_Abc 
from Mytbl
It gives 25-apr-2011 05: 23: 45 pm But when it is ...

68. POI - How do I set cell value to Date and apply default Excel date format?

I've been using Apache POI for some time to read existing Excel 2003 files programmatically. Now I have a new requirement to create entire .xls files in-memory (still using Apache POI) ...

69. date format in java

I want to convert Date in different Format. For example, String fromDate = "2011-04-22"; I want to convert this fromDate as "22nd Apr, 2011" How can I do this? Thanks in Advance

70. Date format in java

Possible Duplicate:
how to convert seconds_since_the_beginning_of_this_epoch to date format in java..?
hi i have "1304054138" in ssboetod . I want to display it in this ...

71. What about TimeFormat? Converting Timestamp

How to format a java.sql Timestamp for displaying ? What about TimeFormat, how can I convert a Timestamp as a String showing the time?

72. I want a date format "yyyy-MMM-dd HH:mm:ss a" in Japanese

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;

public class DateFormatExample4 {

public SimpleDateFormat makeDateFormatter(
          String pattern, Locale l,TimeZone tz)
    SimpleDateFormat sdf ...

73. java program to accept any format of date as input and print the month,

java program to accept any format of date as input and print the month, Is it possible I tried the following,any other alternative ways/ideas??

import java.text.*;

import java.util.*;

public class PrintMonth3{

    public static ...

74. How to convert a date in this format (Tue Jul 13 00:00:00 CEST 2010) to a Java Date (The string comes from an alfresco property)

i'm managing a date that comes from an Alfresco Properties and is in the specified (Tue Jul 13 00:00:00 CEST 2010) and i need to convert it to a Java date...i've ...

75. Date format in Java

Few questions:

  1. How can I print now (The current Date/Time) in the format below.
  2. How can I convert a string date, into a date object if I know the format, same format as ...

76. Date Format from Date in String to Date

Possible Duplicate:
String to Date in Different Format in Java
Hi, I m receiving date as String data type in MM/dd/yyyy format and need to convert in ...

77. Convert Hippo JCR datetime to Java format

I use JCR Query to get some news from Hippo repository. and as result I getting date in this format:

can someone tell me how can I convert it to like this:
07-04-2011 ...

78. Formatting Dates using a Format class (or otherwise if )

i want to use standard class called DateFormat which has subclass SimpleDateFormat TO write a method called convert which returns a String in the form when passed a GregorianCalendar with ...

79. Help Needed with Date Format in java

I have My Database data in this format 18-NOV-10 I have to pass the same format into java.util.Date like this Date date = new java.util.Date(dateformater); so that the result of java.util.Date is ...

80. Java Date conversion

Possible Duplicate:
Java string to date conversion
Hi, how would I convert a string, for example "5/22/2011" into Sunday, May 22? Thanks in advance!

81. How to convert complex date string into datetime java

I have the following string that I need put into a date time Sat, 21-May-2011 21:31:35 GMT So far I'm doing the following but I'm not sure of the valid format to get ...

82. change string to date as per the required date Format

I have to get a Date in type Date, not in String. I have this code:

DateFormat formatter = new SimpleDateFormat("MM/dd/yy");
Date date1 = new Date();
String date = (formatter.format(date1));
// At this point I get ...

83. JodaTime date formatting issue

I am formatting my date as follows:

String inputDateString = aMessage.getString("updated_at");

84. How to format Date field in POJO while creating a BeanMap out of the POJO?

If I have a POJO with a Date field, when I constrcut a BeanMap, the value of the field is cast to milliseconds. How can I easily include the desired date format ...

85. Does simple date format support this conversion?

I am getting this Date as String

String str = "Fri May 13 2011 19:59:09 GMT 0530 (India Standard Time)";
How to convert this Date Object into the format: yyyy-mm-dd HH24:Mi:ss? I have not ...

86. Convert Date format from "29/05/2011 00:00:00 ZE8" into "Sat, 28 May 2011"in Java

I am struggling to convert my String "29/05/2011 00:00:00 ZE8" into the following format in "Sat, 28 May 2011" in Java. This is an abstract of my code. It seems to work ...

87. Invalid format error when converting string to a DateTime object using joda time api

Using joda time library im trying converted a string of the form "04/02/2011 20:27:05" to a DateTime object.Following the responses to my question at Converting a date string to a ...

88. display Java.util.Date in a specific format

I have the following scenario :

SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
gives an output
Tue May 31 00:00:00 SGT 2011
but I want the output to be
I need to use parse here ...

89. how to retrieve day month and year from Timestamp(long format)

I need to retrieve day year and month from a timestamp object as long numbers:

public long getTimeStampDay()


90. Date format with Java

Possible Duplicate:
format date from 14 aug to YYYYMMDD
Hi I need to get a date in a YYYYMMDD format. I Don't know the right method ...

91. Convert long time difference to format HH:mm [Java]

How can I convert the difference of the current time a given time to create a string with the time format: HH:mm ? ex. 18:36 I did the following but, it ...

92. Java parsing a date like Thursday, May 29, 2008 1:45 PM into a more usable format?

I need to parse dates like Thursday, May 29, 2008 1:45 PM for a current project and don't have much time get it done. I realize I can write some custom ...

93. Fixed length of month and day in date format?

Is there any way to format Date object to made fixed length of Day and Month in order to have good alignment in a column? For example:

15 May     ...

94. Date in java with just year

My aim is to get a date in the format '{current year}-01-01 00:00:00' i.e. only the value for year changes with time. What is the best way to do that. Using

SimpleDateFormat simpleDateFormat ...

95. Convert DATE Format to Epoch

Hi I have a string of Date format

Jun 13 2003 23:11:52.454 UTC
containing millisec...which i want to convert in epoch. Is there a utility in Java i can use to do ...

96. Convert HHMM String to GMT format in Java

I need to convert a String of the form HHMM (in EST or EDT - today) into a GMT timestamp of the form YYYYMMDD-HH:MM:SS. So if I get 1512, I ...

97. Convert String to String with a Date Format in Java?

I am writing a application where I want to convert a string "2011-07-17 08:05:50" to "Jul 17 08:05AM". Is there a direct way to do it in Java. I want both ...

98. converting date time to 24 hour format

The time i get from the server is like Jul 27, 2011 8:35:29 AM .I want to convert it to yyyy-MM-dd HH:mm:ss.I also want the converted time to be in ...

99. GSON - Date format

I'm trying to have a custom date format in Gson output, but .setDateFormat(DateFormat.FULL) doesn't seem to work and it the same with .registerTypeAdapter(Date.class, new DateSerializer()). It's like Gson doesn't care about the ...

100. How to display date and time(12 hour format) from seconds in java

Hi i have seconds as follows

long seconds = 1299671538L;
using the above seconds i want to display the date and time(12 hour format).I have written code as follows
    SimpleDateFormat ...