以下代码使用尤达-时间库
Long timestamp = DateTime.parse(dateInString,DateTimeFormat.shortTime()).getMillis();生成:
java.lang.IllegalArgumentException: Invalid format: "12.05.2014 11:42:35.808" is malformed at ".05.2014 11:42:35.808"我尝试了所有的DateTimeFormat.*,但是每种格式都会产生错误。
怎么修呢?
发布于 2014-06-27 12:50:20
构建一个与您的模式相匹配的DateTimeFormatter,并使用它。你的模式当然不是“短时间”模式,因为你也有约会.
例如:
// Possibly MM.dd.yyyy - we don't know what 12.05.2014 is meant to represent
DateTimeFormatter formatter = DateTimeFormat.forPattern("dd.MM.yyyy HH:mm:ss.SSS");
.withLocale(Locale.US)
.withZoneUTC(); // Adjust accordingly
DateTime dateTime = formatter.parse(text);
long millis = dateTime.getMillis();发布于 2014-06-27 12:56:37
尝尝这个
DateTimeFormatter pattern = DateTimeFormat.forPattern("dd.MM.yyy hh:mm:ss.SSS");
Long timestamp = DateTime.parse(dateInString,pattern).getMillis();发布于 2014-06-27 12:59:29
import java.util.*;
import java.text.*;
Date DateNow= new Date( );
SimpleDateFormat sdf =new SimpleDateFormat ("yyyy.MM.dd hh:mm:ss");
String timestamp= sdf.format(DateNow);https://stackoverflow.com/questions/24452107
复制相似问题