Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Ron McLeod
Jeanne Boyarsky
Sheriffs:
Paul Clapham
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Beginning Java
SimpledateFormat class issue.
Tontang Bei
Ranch Hand
Posts: 130
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
package util; import java.util.*; import java.text.*; public class Testit{ public static void main(String[] args){ new Testit().test(); } public void test(){ String input="2007-12-05"; Date d1=parseIt(input); Calendar c=Calendar.getInstance(); c.setTime(d1); System.out.println("yyyy="+c.get(c.YEAR)); o/p yyyy=2007 OK System.out.println("mm="+c.get(c.MONTH)); o/p mm=0 <--NOT OK System.out.println("dd="+c.get(c.DATE)); o/p dd=5 OK } public Date parseIt(String dateTobeParsed){ Date date=null; try{ DateFormat formatter = new SimpleDateFormat("yyyy-mm-dd"); date = (Date)formatter.parse(dateTobeParsed); }catch(ParseException ps){System.out.println(ps);} return date; } }
The output I get is:
yyyy=2007
mm=0
dd=5
the month is shown as 0. The month should be shown as 12. Please help
Srikanth Ramu
Ranch Hand
Posts: 76
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
For month the representation is MM and m represents minute in hour. For more details refer:
http://java.sun.com/j2se/1.5.0/docs/api/java/text/SimpleDateFormat.html
Tontang Bei
Ranch Hand
Posts: 130
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Convert date in difference format
System Date
Code review required for converting dateformat
cannot find symbol
Months and years
More...