我目前正在使用Firestore处理聊天应用程序。当我尝试从firestore文件中获取Timestamp时
日期date=documentSnapshot.getDate(fieldvalue1,DocumentSnapshot.ServerTimestampBehavior.ESTIMATE);
然后它在“Mon Sep 17 05:52:14 EDT 2018”这个格式返回日期。我无法将该日期转换为简单日期格式。请帮忙。
您可以使用EEE MMM dd HH:mm:ss z yyyy
模式从字符串中检索日期。喜欢,
SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.US);
try {
Date date2 = format.parse(dateStr);
} catch (ParseException e) {
e.printStackTrace();
}
编辑
你可以转换成印度时间喜欢,
SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.US);
try {
format.setTimeZone(TimeZone.getTimeZone("GMT-04:00")); //for EDT
Date date2 = format.parse(dateStr);
TimeZone tz = TimeZone.getTimeZone("GMT+5:30"); //for Indian Time
format.setTimeZone(tz);
String result = format.format(date2);
} catch (ParseException e) {
e.printStackTrace();
}