解决方案
使用 Date.parse()
//English formatter var stringValue = "2010.10.06" var dateCommonFormatter : DateFormatter = new DateFormatter(); dateCommonFormatter.formatString = "YYYY/MM/DD"; var formattedStringValue : String = dateCommonFormatter.format(stringValue); var dateFromString : Date = new Date(Date.parse(formattedStringValue));
如果是符号‘-’,我们先进行字符替换
private function castMethod4(dateString:String):Date { if ( dateString == null ) return null; if ( dateString.length != 10 && dateString.length != 19) return null; dateString = dateString.replace("-", "/"); dateString = dateString.replace("-", "/"); return new Date(Date.parse( dateString )); }
日期:2020-03-24 13:58:07 来源:oir作者:oir