datetime - How to convert String time stamp to java.sql.Timestamp? -


i have time stamp in string format "thu, 23 feb 2017 04:56:38 gmt". so, how can convert string time stamp "2017-02-23 04:56:38.0" format. tried link java converting date in string format timestamp . facing error in conversion. sample code below.

string str = "thu, 23 feb 2017 04:56:38 gmt";       simpledateformat sdf1 = new simpledateformat("eee, dd mmm yyyy hh:mm:ss a");     date date = null;     try {         date = (date) sdf1.parse(str);     } catch (parseexception e) {         // todo auto-generated catch block         e.printstacktrace();     }     system.out.println("date object:" + date);     simpledateformat sdf2 = new simpledateformat("yyyy-mm-dd hh:mm:ss");     system.out.println("formatted date:" + sdf2.format(date)); 

error: java.text.parseexception: unparseable date: "thu, 23 feb 2017 04:56:38 gmt" @ java.text.dateformat.parse(dateformat.java:366)

just change sdf1 format

simpledateformat sdf1 = new simpledateformat("eee, dd mmm yyyy hh:mm:ss z"); 

here z means

date or time component  presentation        examples time zone               general time zone   pacific standard time; pst; gmt-08:00 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -