我试图添加日期到textview自动,但它给我一个旧的日期,如1/1/1970不是当前日期
代码
private long date;
private DateFormat format;
String currentDateandTime;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SimpleDateFormat datef = new SimpleDateFormat("dd/MM/yyyy");
String currentDateandTime = datef.format(new Date(date));
TextView set_date = (TextView) findViewById(R.id.set_date);
Calendar ca = Calendar.getInstance();
SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
try {
set_date.setText(format.format(new Date(date)));
} catch (ParseException e) {
e.printStackTrace();
}
那么我怎样才能使这段代码加载设备的当前日期而不是这个旧日期呢?
更改自:
try {
set_date.setText(format.format(new Date(date)));
} catch (ParseException e) {
e.printStackTrace();
}
try {
set_date.setText(format.format(ca.getTime()));
} catch (ParseException e) {
e.printStackTrace();
}