我的Date
构造函数已弃用并以黄色突出显示。
如何使用Calendar.Set()
解决此问题。我打电话给import java.util.Calendar
;和date
。
代码如下。提前致谢。
Format f = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
Date d = new Date(f.format(geoState.getString("fireTime")));
temp.setFireTime(d);
答案 0 :(得分:2)
使用DateFormat.parse
方法将String
转换为Date
String string = "January 2, 2010";
DateFormat format = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH);
Date date = format.parse(string);
System.out.println(date);
在你的情况下,它将是这样的
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
Date date = format.parse(geoState.getString("fireTime"));
temp.setFireTime(date);
答案 1 :(得分:0)
将项目迁移到Java 11时遇到相同的问题。这是答案
新日期(“ 08/10/2020”);
到
DateFormat.getDateInstance()。parse(“ 08/10/2020”)