java - How to convert a given date & time in standard format to unix time? -


i creating program converting given time , date unix time... getting error as- java.time package not exist on line-

s = java.time.instant.parse(l[0]).getepochsecond(); 

using java 8 api

public class test{     public static void main(string args[]){         string strdate = "jun 13 2003 23:11:52.454 utc";         datetimeformatter dtf  = datetimeformatter.ofpattern("mmm dd yyyy hh:mm:ss.sss zzz");         zoneddatetime     zdt  = zoneddatetime.parse(strdate,dtf);                 system.out.println(zdt.toinstant().toepochmilli());  // 1055545912454       } 

for previous java versions

public static void main(string[] args) throws exception {     string str = "jun 13 2003 23:11:52.454 utc";     simpledateformat df = new simpledateformat("mmm dd yyyy hh:mm:ss.sss zzz");     date date = df.parse(str);     long epoch = date.gettime();     system.out.println(epoch); // 1055545912454 } 

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -