Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.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 第25偏移处的不可拆分日期_Java_Date Format_Parseexception - Fatal编程技术网

Java 第25偏移处的不可拆分日期

Java 第25偏移处的不可拆分日期,java,date-format,parseexception,Java,Date Format,Parseexception,我很难解决这个问题。我正在尝试将日期字符串2013-05-23T19:00:00GMT-00解析为标准格式,即yyyy-MM-dd'T'HH:MM:ssz,但我总是在位置25处收到ParseException // Get a human readable format. DateFormat dateFormat = DateTime.getStandardFormat(); // Subtract a full hour from the time passed i

我很难解决这个问题。我正在尝试将日期字符串
2013-05-23T19:00:00GMT-00
解析为标准格式,即
yyyy-MM-dd'T'HH:MM:ssz
,但我总是在位置25处收到ParseException

    // Get a human readable format.
    DateFormat dateFormat = DateTime.getStandardFormat();

    // Subtract a full hour from the time passed in.
    final int HOUR_IN_MINUTES = 3600;
    DateTime dateTimeLess1Hour = aDateTime.minus(HOUR_IN_MINUTES, 0);

    // Convert the DateTime, less exactly one hour, to a string.
    String timeLess1String = dateFormat.format(DateTime.toDate(dateTimeLess1Hour));

    // Split the string to distinguish the time part
    String date = timeLess1String.substring(0, 10);
    String time = timeLess1String.substring(11);

    String[] hhMMss = time.split(":");

    String hourOnHourDate = date + "T" + hhMMss[0] + ":00:00" + hhMMss[2].substring(2);

    Date inDateFormat = null;

    // Convert the string into a Date object
    inDateFormat = dateFormat.parse(hourOnHourDate);

    // Convert the Date into a DateTime object.
    return new DateTime(inDateFormat);

错误消息显示不可解析日期:2013-05-23T19:00:00GMT-00

位置25表示
GMT
部分的开始,该部分是您尝试使用字母
z
解析的部分。如果您确定您的时区始终为
GMT
,则可以将其作为固定字符串,如下所示:

yyyy-MM-dd'T'HH:mm:ss'GMT'
如果输入时区有时会不同,则将其分开

String zone = inputTime.substring(startPosition, endPosition);

并使用
zone
string

在单独的行中设置时区,尝试使用SimpleDataFormat,可能是DateTime有一些问题。。。也应该是GMT-00:00Dhrubajyoti,谢谢,我在字符串的末尾添加了额外的:00,这就解决了错误。