java - Formatting date with time zone. Wrong format -
java - Formatting date with time zone. Wrong format -
i have tried many different types of solutions using java.text.simpledateformat couldn't quite right.
the input string receive tue nov 5 00:00:00 utc+0530 2013
. format want dd-mmm-yy
. below code use:
simpledateformat formatter = new simpledateformat("eee mmm d hh:mm:ss zz yyyy", locale.english); date = formatter.parse(s); system.out.println(date);
i receive error: unreported exception parseexception; must caught or declared thrown date = formatter.parse(s);
i tried lot of alter in formats still receive error. can please allow me know exact format of string passing?
handle exceptions
you have not handled exceptions in code. why compiler gives errors. need handle parseexception may thrown during parsing.
simpledateformat formatter = new simpledateformat("eee mmm d hh:mm:ss zz yyyy", locale.english); try{ date = formatter.parse(s); system.out.println(date); }catch(parseexception ex){ //exception ex.printstacktrace(); }
or can add together throws parseexception
method .
according comment seems trying convert date[string] format. if right next illustration may help you.
string inputstring="tue nov 5 00:00:00 utc+0530 2013"; simpledateformat formatter = new simpledateformat("eee mmm d hh:mm:ss zz yyyy", locale.english); dateformat outformat = new simpledateformat("dd-mmm-yy"); seek { string result = outformat.format(formatter.parse(inputstring)); system.out.println(result); } grab (parseexception ex) { ex.printstacktrace(); }
output:
class="lang-none prettyprint-override">04-nov-13
java
Comments
Post a Comment