File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Spring in Action
this week in the
Java in General
Problem with Date Format
Joined: Apr 09, 2007
Apr 16, 2008 08:52:00
Iam converting the date to MM/dd/yyyy format and converting it back to date and iam getting starnge results. Can someone correct where iam doing wrong?
Code snippet is below. Iam taking today's date: 04/16/2008
Calendar d1 = new
System.out.println("Date is "+ d1.getTime());
str1 = df.format(d1.getTime());
System.out.println("SHORT Style = " + str1);
==> Date is Wed Apr 16 10:44:50 EDT 2008
==> SHORT Style = 4/16/08
// now iam converting the date again from String to Date.
sdf = new
Date d111 = sdf.parse(str1, new
System.out.println("d111 = "+d111);
==> d111 = Mon Apr 16 00:00:00 EDT 0008
Its printing "Mon". what is wrong with the code?
Joined: Jun 09, 2006
Apr 16, 2008 09:08:00
Its also printing year 0008 (rather than 2008). The short date format does not include the century (i.e. 2000 or 1900) and when you make it make into a date it assumes the century is 0.
Joined: Oct 12, 2001
Apr 16, 2008 10:16:00
with the same date
in both format and parse method.
Regards, Rene Larsen
I agree. Here's the link:
subject: Problem with Date Format
string to date parsing ....
Time Zone problem
How to change Date Format
Help for using Java Time
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014