将字符串日期解析为long java

时间:2014-12-12 12:01:40

标签: string parsing date long-integer

我有String date = dd/MM/yyyy。我该如何解析它?我有没有得到这一天,解析得很久,得到月份,解析得很久,得到年份,解析得很久然后连接?

谢谢,

2 个答案:

答案 0 :(得分:2)

使用Formatter解析日期:

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

答案 1 :(得分:0)

使用simpledateformat可以轻松实现此目的

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

了解更多信息,请点击Here