Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/188.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从字符串解析日期以获取毫秒_Java_Android_Android Calendar_Android Date_Java Time - Fatal编程技术网

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();它将以毫秒为单位给出时间。