的Android / Java的字符串转换日期为long类型 [英] Android / Java convert String date to long type
本文介绍了的Android / Java的字符串转换日期为long类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个字符串转换格式为DD / MM / YYYY,为长型。为了将值传递给calendarProvider在android系统。
I need to convert a string in the format "dd/mm/yyyy", to a long type. In order to pass the value to the calendarProvider in android.
目前我有:
Calendar calendar = Calendar.getInstance();
long startEndDate = 0;
Calendar currentDateInfo = Calendar.getInstance();
currentDateInfo.set(calendar.get(Calendar.YEAR), calendar.SEPTEMBER, calendar.get(Calendar.DAY_OF_MONTH));
startEndDate = currentDateInfo.getTimeInMillis();
我需要:
long startDate = *Some sort of conversion* EditText.getText();
我一直使用的SimpleDateFormat试过,但我有得到正确的类型背部问题。任何帮助将是非常美联社preciated。
I've tried using SimpleDateFormat but i'm having problems getting the correct type back. Any help would be much appreciated.
推荐答案
您可以使用以下code得到(自1970年1月1日,00:00:00 GMT毫秒)从字符串日期长期价值格式为DD / MM / YYYY。
You can use the following code to get a long value (milliseconds since January 1, 1970, 00:00:00 GMT) from a String date with the format "dd/mm/yyyy".
try {
String dateString = "30/09/2014";
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
Date date = sdf.parse(dateString);
long startDate = date.getTime();
} catch (ParseException e) {
e.printStackTrace();
}
这篇关于的Android / Java的字符串转换日期为long类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文