How to convert a string Date to long millseconds

前端 未结 9 2135
你的背包
你的背包 2020-11-29 07:40

I have a date inside a string, something like \"12-December-2012\". How can I convert this into milliseconds (long)?

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-29 08:38

    using simpledateformat you can easily achieve it.

    1) First convert string to java.Date using simpledateformatter.

    2) Use getTime method to obtain count of millisecs from date

     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();
      }
            }
    

    more Example click here

提交回复
热议问题