简体   繁体   中英

parse String date to long java

I have a String date = dd/MM/yyyy . How can I parse it to long? Have I to get the day, parse to long, get the month, parse to long, get the year, parse to long and then concatenate?

Thanks,

Use the Formatter to parse the date:

DateFormat df = new SimpleDateFormat("dd/MM/yyy");
Long date = df.parse("12/12/2014").getTime();

using simpledateformat you can easily achieve this

public class test {
public static void main(String[] args) {

     String currentDate = "01-March-2016";
     SimpleDateFormat f = new SimpleDateFormat("dd-MMM-yyyy");
     Date parseDate = f.parse(currentDate);
     long milliseconds = parseDate.getTime();
}
}

for More information click Here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM