Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error on converting string to date in java

2014-04-23T18:30:00.000Z need to convert in this format yyyy-MM-dd'T'hh:mm:sszzz in java

I am using this

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.zzzZ");
Date newfromDate = new Date();
try {
    //Convert into date 
    newfromDate = (Date)formatter.parse(fromDate);

    // get required Format of date in string format 
    SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:sszzz");
} catch (ParseException e) {
    e.printStackTrace();
}

but this is not working

error :- java.text.ParseException: Unparseable date: "2014-03-31T18:30:00.000Z"

like image 996
Er KK Chopra Avatar asked Apr 11 '26 06:04

Er KK Chopra


1 Answers

try this

new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX").parse(s);

or this

javax.xml.bind.DatatypeConverter.parseDateTime("2014-04-23T18:30:00.000Z");

the last version is supposed to be faster (no need to parse pattern) and thread-safe

like image 145
Evgeniy Dorofeev Avatar answered Apr 13 '26 19:04

Evgeniy Dorofeev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!