Java 从字符串解析日期以获取毫秒
我试图从包含日期的字符串中获取毫秒数,但似乎得到了错误的值。这是我试图解析的字符串:Java 从字符串解析日期以获取毫秒,java,android,android-calendar,android-date,java-time,Java,Android,Android Calendar,Android Date,Java Time,我试图从包含日期的字符串中获取毫秒数,但似乎得到了错误的值。这是我试图解析的字符串:2015-03-01 00:00:00, 我这样做是为了分析它: DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss"); Date inputDate = dateFormat.parse(data.get(position).getValidTo()); Log.d("--", inputDate.getDay() + "
2015-03-01 00:00:00
,
我这样做是为了分析它:
DateFormat dateFormat = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
Date inputDate = dateFormat.parse(data.get(position).getValidTo());
Log.d("--", inputDate.getDay() + " | " + inputDate.getMonth());
使用“MM”
而不是“MM”
获取月份。(“mm”代表分钟)
和inputDate.getTime()
将以毫秒为单位给出时间。使用“MM”
而不是“MM”
获得月份。(“mm”代表分钟)
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date inputDate = dateFormat.parse("2014-10-12 12:00:00");
System.out.println(inputDate.getTime());
和inputDate.getTime()
将以毫秒为单位给出时间。使用“MM”
而不是“MM”
获得月份。(“mm”代表分钟)
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date inputDate = dateFormat.parse("2014-10-12 12:00:00");
System.out.println(inputDate.getTime());
和inputDate.getTime()
将以毫秒为单位给出时间。使用“MM”
而不是“MM”
获得月份。(“mm”代表分钟)
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date inputDate = dateFormat.parse("2014-10-12 12:00:00");
System.out.println(inputDate.getTime());
而
inputDate.getTime()
将以毫秒为单位给出时间。如果您添加依赖项,我将使用它来执行任何与日期相关的操作
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
Date inputDate = dateFormat.parse("2014-10-12 12:00:00");
System.out.println(inputDate.getTime());
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
用这个
String input = "2015-03-01 00:00:00";
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
DateTime dt = DateTime.parse(input, formatter);
System.out.println(dt.getDayOfWeek());
System.out.println(dt.getMonthOfYear());
如果您添加依赖项,我将使用它来执行任何与日期相关的操作
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
用这个
String input = "2015-03-01 00:00:00";
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
DateTime dt = DateTime.parse(input, formatter);
System.out.println(dt.getDayOfWeek());
System.out.println(dt.getMonthOfYear());
如果您添加依赖项,我将使用它来执行任何与日期相关的操作
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
用这个
String input = "2015-03-01 00:00:00";
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
DateTime dt = DateTime.parse(input, formatter);
System.out.println(dt.getDayOfWeek());
System.out.println(dt.getMonthOfYear());
如果您添加依赖项,我将使用它来执行任何与日期相关的操作
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
用这个
String input = "2015-03-01 00:00:00";
DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss");
DateTime dt = DateTime.parse(input, formatter);
System.out.println(dt.getDayOfWeek());
System.out.println(dt.getMonthOfYear());
你从中得到了什么?你想要
yyyy-MM-dd HH:MM:ss
。然后不要在Date
上使用不推荐的方法。。。你只是自找麻烦。请包括日志文件。并记录data.get(position).getValidTo()的内容,以检查字符串是否正确valid@MichałSzydłowski当我执行Log.d(“-”,inputDate.getDay()+“|”+inputDate.getMonth())
I获取4 | 0
inputDate.getTime();它将以毫秒的形式给出时间。你从中得到了什么?你想要yyyy-MM-dd HH:MM:ss
。然后不要在Date
上使用不推荐的方法。。。你只是自找麻烦。请包括日志文件。并记录data.get(position).getValidTo()的内容,以检查字符串是否正确valid@MichałSzydłowski当我执行Log.d(“-”,inputDate.getDay()+“|”+inputDate.getMonth())
I获取4 | 0
inputDate.getTime();它将以毫秒的形式给出时间。你从中得到了什么?你想要yyyy-MM-dd HH:MM:ss
。然后不要在Date
上使用不推荐的方法。。。你只是自找麻烦。请包括日志文件。并记录data.get(position).getValidTo()的内容,以检查字符串是否正确valid@MichałSzydłowski当我执行Log.d(“-”,inputDate.getDay()+“|”+inputDate.getMonth())
I获取4 | 0
inputDate.getTime();它将以毫秒的形式给出时间。你从中得到了什么?你想要yyyy-MM-dd HH:MM:ss
。然后不要在Date
上使用不推荐的方法。。。你只是自找麻烦。请包括日志文件。并记录data.get(position).getValidTo()的内容,以检查字符串是否正确valid@MichałSzydłowski当我执行Log.d(“-”,inputDate.getDay()+“|”+inputDate.getMonth())
I获取4 | 0
inputDate.getTime();它将以毫秒为单位给出时间。