在本文中,我们将详细介绍java.text.ParseException:无法解析的日期“yyyy-MM-dd'T'HH:mm:ss.SSSZ”-SimpleDateFormat的各个方面,同时,我们
在本文中,我们将详细介绍java.text.ParseException:无法解析的日期“ yyyy-MM-dd'T'HH:mm:ss.SSSZ”-SimpleDateFormat的各个方面,同时,我们也将为您带来关于c# – 日期格式yyyy-MM-ddTHH:mm:ssZ、Date可以SimpleDateFormat("MM/dd/yyyy HHss"),那能不能反过来、dd-MMM-yyyy格式的java.time.format.DateTimeParseException、flex – Actionscript 3 – 解析yyyy-mm-dd hh:mm:ss到Date对象的最快方法?的有用知识。
本文目录一览:- java.text.ParseException:无法解析的日期“ yyyy-MM-dd'T'HH:mm:ss.SSSZ”-SimpleDateFormat
- c# – 日期格式yyyy-MM-ddTHH:mm:ssZ
- Date可以SimpleDateFormat("MM/dd/yyyy HHss"),那能不能反过来
- dd-MMM-yyyy格式的java.time.format.DateTimeParseException
- flex – Actionscript 3 – 解析yyyy-mm-dd hh:mm:ss到Date对象的最快方法?
java.text.ParseException:无法解析的日期“ yyyy-MM-dd'T'HH:mm:ss.SSSZ”-SimpleDateFormat
如果能找到有关此异常的错误的帮助,我将不胜感激:
java.text.ParseException: Unparseable date: "2007-09-25T15:40:51.0000000Z"
和以下代码:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd''T''HH:mm:ss.SSSZ");Date date = sdf.parse(timeValue);long mills = date.getTime();this.point.time = String.valueOf(mills);
它用引发异常Date date = sdf.parse(timeValue);
。
timeValue = "2007-09-25T15:40:51.0000000Z";
,作为例外。
谢谢。
答案1
小编典典Z
代表时区字符。需要引用:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd''T''HH:mm:ss.SSS''Z''");
c# – 日期格式yyyy-MM-ddTHH:mm:ssZ
在这种格式中,Z是时区.
T是长时间模式
除了使用之外,我怎么能得到这种格式的日期
DateTime dt = DateTime.Now; Console.WriteLine(dt.ToString("yyyy-MM-ddTHH:mm:ssZ"));
在C#中
解决方法
ISO 8601(MSDN datetime formats)
Console.WriteLine(DateTime.UtcNow.ToString("s") + "Z");
2009-11-13T10:39:35Z
Z就在那里因为
If the time is in UTC,add a ‘Z’
directly after the time without a
space. ‘Z’ is the zone designator for
the zero UTC offset. “09:30 UTC” is
therefore represented as “09:30Z” or
“0930Z”. “14:45:15 UTC” would be
“14:45:15Z” or “144515Z”.
如果要包含偏移量
int hours = TimeZoneInfo.Local.BaseUtcOffset.Hours; string offset = string.Format("{0}{1}",((hours >0)? "+" :""),hours.ToString("00")); string isoformat = DateTime.Now.ToString("s") + offset; Console.WriteLine(isoformat);
有两点需要注意:或者 – 在时间之后需要 – 但显然不会显示正数.根据维基百科,偏移可以是hh格式或hh:mm.我一直待上几个小时.
据我所知,RFC1123(HTTP日期,“你”格式化程序)并不意味着给出时区偏移.所有时间都是GMT / UTC.
Date可以SimpleDateFormat("MM/dd/yyyy HHss"),那能不能反过来
把Date转成时间格式的MM/dd/yyyy HHss 那能不能时间格式的转成Date的?dd-MMM-yyyy格式的java.time.format.DateTimeParseException
我正在尝试解析dd-MMM-yyyy
格式的日期。
package com.company;import javax.swing.text.DateFormatter;import java.time.format.DateTimeFormatter;import java.time.*;import java.util.Locale;public class Main { public static void main(String[] args) { // write your code here MonthDay m; Locale.setDefault(Locale.ENGLISH); DateTimeFormatter dTF = DateTimeFormatter.ofPattern("dd-MMM-yyyy"); String dateString = "12-jan-1900"; try { LocalDate ddd = LocalDate.parse(dateString,dTF); System.out.println(ddd.toString()); } catch (Exception e) { e.printStackTrace(); } //System.out.println(d.toString()); }}
它引发以下异常
java.time.format.DateTimeParseException: Text ''12-jan-1900'' could not be parsed at index 3 at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949) at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851) at java.time.LocalDate.parse(LocalDate.java:400) at com.company.Main.main(Main.java:20) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
它可以解析dd-MM-yyyy
格式,但是格式失败dd-MMM-yyyy
。我Locale.US
也很累设定,但是在那种情况下也失败了。
答案1
小编典典原因是解析默认情况下区分大小写,并且格式化程序无法识别"jan"
。它只会识别"Jan"
。
您可以使用DateTimeFormatterBuilder
并调用来构造不区分大小写的解析器parseCaseInsensitive()
:
将格式样式的其余部分的解析样式更改为不区分大小写。
解析可以区分大小写或不区分大小写-默认情况下区分大小写。此方法允许更改区分大小写的解析设置。
DateTimeFormatter dTF = new DateTimeFormatterBuilder().parseCaseInsensitive() .appendPattern("dd-MMM-yyyy") .toFormatter();
flex – Actionscript 3 – 解析yyyy-mm-dd hh:mm:ss到Date对象的最快方法?
有没有人知道这样做的更快的方法或提示加快方法?
castMethod1 takes 3673 ms castMethod2 takes 3812 ms castMethod3 takes 3931 ms
码:
private function castMethod1(dateString:String):Date { if ( dateString == null ) { return null; } var year:int = int(dateString.substr(0,4)); var month:int = int(dateString.substr(5,2))-1; var day:int = int(dateString.substr(8,2)); if ( year == 0 && month == 0 && day == 0 ) { return null; } if ( dateString.length == 10 ) { return new Date(year,month,day); } var hour:int = int(dateString.substr(11,2)); var minute:int = int(dateString.substr(14,2)); var second:int = int(dateString.substr(17,2)); return new Date(year,day,hour,minute,second); }
–
private function castMethod2(dateString:String):Date { if ( dateString == null ) { return null; } if ( dateString.indexOf("0000-00-00") != -1 ) { return null; } dateString = dateString.split("-").join("/"); return new Date(Date.parse( dateString )); }
–
private function castMethod3(dateString:String):Date { if ( dateString == null ) { return null; } var mainParts:Array = dateString.split(" "); var dateParts:Array = mainParts[0].split("-"); if ( Number(dateParts[0])+Number(dateParts[1])+Number(dateParts[2]) == 0 ) { return null; } return new Date( Date.parse( dateParts.join("/")+(mainParts[1]?" "+mainParts[1]:" ") ) ); }
不,默认情况下,Date.parse不会处理破折号。而且我需要为“0000-00-00”之类的日期时间字符串返回null。
解决方法
private function parseUTCDate( str : String ) : Date { var matches : Array = str.match(/(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)Z/); var d : Date = new Date(); d.setUTCFullYear(int(matches[1]),int(matches[2]) - 1,int(matches[3])); d.setUTCHours(int(matches[4]),int(matches[5]),int(matches[6]),0); return d; }
只需删除时间部分,它应该适合您的需要:
private function parseDate( str : String ) : Date { var matches : Array = str.match(/(\d\d\d\d)-(\d\d)-(\d\d)/); var d : Date = new Date(); d.setUTCFullYear(int(matches[1]),int(matches[3])); return d; }
不知道速度,我没有在我的应用程序中担心。在我的机器上显着少于一秒的50K次迭代。
我们今天的关于java.text.ParseException:无法解析的日期“ yyyy-MM-dd'T'HH:mm:ss.SSSZ”-SimpleDateFormat的分享就到这里,谢谢您的阅读,如果想了解更多关于c# – 日期格式yyyy-MM-ddTHH:mm:ssZ、Date可以SimpleDateFormat("MM/dd/yyyy HHss"),那能不能反过来、dd-MMM-yyyy格式的java.time.format.DateTimeParseException、flex – Actionscript 3 – 解析yyyy-mm-dd hh:mm:ss到Date对象的最快方法?的相关信息,可以在本站进行搜索。
本文标签: