Reading a formatted date as a Calendar or Date object in Java -


this question has answer here:

i'm trying create date or calendar object string representation of date in java. tried using simpledateformat.parse, result produced totally different gave input. can explain i'm doing wrong here?

import java.util.*; import java.lang.*; import java.io.*; import java.text.*; class ideone {   public static void main (string[] args) throws java.lang.exception   {     simpledateformat sdf = new simpledateformat("yyyymmdd");     sdf.settimezone(timezone.gettimezone("gmt"));     date dt = sdf.parse("20141208");     system.out.println(dt.getday() + " " + dt.getmonth() + " " + dt.getyear());     system.out.println(sdf.format(dt));   } } 

i getting output

0 11 113 20141229 

you have use lower y year :

simpledateformat sdf = new simpledateformat("yyyymmdd"); 

because upper y week year. more information read documentation of simpledateformat


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -