我需要将此时间和日期转换为此时间戳格式:
2019/04/22 10:04:30 至 2019-02-21T14:10:18.161+0000
这是我的代码,它不起作用,我错过了一些东西,对吗?
String isoDatePattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(isoDatePattern);
Date d = null;
try {
d = simpleDateFormat.parse("2019/04/22 10:04:30");
}
catch (ParseException e) {
e.printStackTrace();
}
String dateString = simpleDateFormat.format(d);
Log.e("dateString ::::> ",dateString);
最佳答案
您尝试使用输出格式解析输入。未经测试:
String isoInputDatePattern = "yyyy/MM/dd HH:mm:ss";
SimpleDateFormat simpleInputDateFormat = new SimpleDateFormat(isoInputDatePattern);
String isoOutputDatePattern = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
SimpleDateFormat simpleOutputDateFormat = new SimpleDateFormat(isoOutputDatePattern);
Date d = null;
try {
d = simpleInputDateFormat.parse("2019/04/22 10:04:30");
} catch (ParseException e) {
e.printStackTrace();
}
String dateString = simpleOutputDateFormat.format(d);
Log.e("dateString ::::> ",dateString);
关于java - 将日期和时间转换为时间戳格式 java "2019-02-21T14:10:18.161+0000",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55793185/