Evg*_*y S 1 java string android date
我有字符串看起来像:Sun, 27-Oct-2013 11:31:31 GMT
为了让它更简单我做:
if (s.length() > 10)
s = s.substring(5, s.length() - 4);
Run Code Online (Sandbox Code Playgroud)
之后
s = " 27-Oct-2013 11:31:31"
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss");
Date timestamp = null;
try {
timestamp = formatter.parse(s.trim());
} catch (ParseException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
它会遇到异常 java.text.ParseException: Unparseable date: "27-Oct-2013 11:31:31"
您应该为格式化程序指定一个月份拼写为英语的语言环境,否则它将使用您的默认语言环境.
SimpleDateFormat(String pattern)
构造一个新的SimpleDateFormat使用指定的非本地化的模式和DateFormatSymbols与Calendar用户的默认语言环境.
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss", Locale.US);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
75 次 |
| 最近记录: |