Picker 的纪元和日期时间完全关闭
Epoch and Date Time with Picker is completely off
我有一个 DatePicker 和一个 TimePicker。我同时使用它们来为我的后端设置纪元格式的日期。但是当我转换计算出的纪元时,它完全关闭了。
在我的onCreate
whenToTravel = today = Calendar.getInstance();
travelDate = (LinearLayout) findViewById(R.id.travelDate);
travelDate.setOnClickListener(this);
datePicker = new DatePickerDialog(this, this, today.get(Calendar
.YEAR), today.get(Calendar.MONTH), today.get(Calendar
.DAY_OF_MONTH));
selectedDate = (TextView) findViewById(R.id.selectedDate);
travelTime = (LinearLayout) findViewById(R.id.travelTime);
travelTime.setOnClickListener(this);
timePicker = new TimePickerDialog(this, this, today.get(Calendar
.HOUR_OF_DAY), today.get(Calendar.MINUTE), false);
selectedTime = (TextView) findViewById(R.id.selectedTime);
在我的 onDateSet
和 onTimeSet
@Override
public void onDateSet(DatePicker datePicker, int year, int monthOfYear,
int dayOfMonth) {
whenToTravel.set(Calendar.YEAR, year);
whenToTravel.set(Calendar.MONTH, monthOfYear);
whenToTravel.set(Calendar.DAY_OF_MONTH, dayOfMonth);
selectedDate.setText(DATE_FORMAT.format(whenToTravel.getTime()));
//monthOfYear int: The month that was set (0-11) for compatibility
//with Calendar.
}
@Override
public void onTimeSet(TimePicker timePicker, int hour, int minute) {
whenToTravel.set(Calendar.HOUR_OF_DAY, hour);
whenToTravel.set(Calendar.MINUTE, minute);
selectedTime.setText(TIME_FORMAT.format(whenToTravel.getTime()));
}
现在,当我设置 31-May-2016 10:01 AM 时,我得到 1464710433243
作为纪元。使用 http://www.epochconverter.com/。我得到
Assuming that this timestamp is in milliseconds:
GMT: Tue, 31 May 2016 16:00:33.243 GMT
Your time zone: 31/05/2016, 21:30:33 GMT+5:30
我假设我的时区会 return 31/05/2016, 10:01:33 GMT+5:30
我在这里错过了什么?
我认为它可以正常工作,我进行了这一更改,纪元现在显示为
Assuming that this timestamp is in milliseconds:
GMT: Wed, 01 Jun 2016 04:31:23.256 GMT
Your time zone: 01/06/2016, 10:01:23 GMT+5:30
whenToTravel = today = Calendar.getInstance() ;
today.setTime(new Date(System.currentTimeMillis())) ;
我有一个 DatePicker 和一个 TimePicker。我同时使用它们来为我的后端设置纪元格式的日期。但是当我转换计算出的纪元时,它完全关闭了。
在我的onCreate
whenToTravel = today = Calendar.getInstance();
travelDate = (LinearLayout) findViewById(R.id.travelDate);
travelDate.setOnClickListener(this);
datePicker = new DatePickerDialog(this, this, today.get(Calendar
.YEAR), today.get(Calendar.MONTH), today.get(Calendar
.DAY_OF_MONTH));
selectedDate = (TextView) findViewById(R.id.selectedDate);
travelTime = (LinearLayout) findViewById(R.id.travelTime);
travelTime.setOnClickListener(this);
timePicker = new TimePickerDialog(this, this, today.get(Calendar
.HOUR_OF_DAY), today.get(Calendar.MINUTE), false);
selectedTime = (TextView) findViewById(R.id.selectedTime);
在我的 onDateSet
和 onTimeSet
@Override
public void onDateSet(DatePicker datePicker, int year, int monthOfYear,
int dayOfMonth) {
whenToTravel.set(Calendar.YEAR, year);
whenToTravel.set(Calendar.MONTH, monthOfYear);
whenToTravel.set(Calendar.DAY_OF_MONTH, dayOfMonth);
selectedDate.setText(DATE_FORMAT.format(whenToTravel.getTime()));
//monthOfYear int: The month that was set (0-11) for compatibility
//with Calendar.
}
@Override
public void onTimeSet(TimePicker timePicker, int hour, int minute) {
whenToTravel.set(Calendar.HOUR_OF_DAY, hour);
whenToTravel.set(Calendar.MINUTE, minute);
selectedTime.setText(TIME_FORMAT.format(whenToTravel.getTime()));
}
现在,当我设置 31-May-2016 10:01 AM 时,我得到 1464710433243
作为纪元。使用 http://www.epochconverter.com/。我得到
Assuming that this timestamp is in milliseconds: GMT: Tue, 31 May 2016 16:00:33.243 GMT Your time zone: 31/05/2016, 21:30:33 GMT+5:30
我假设我的时区会 return 31/05/2016, 10:01:33 GMT+5:30
我在这里错过了什么?
我认为它可以正常工作,我进行了这一更改,纪元现在显示为
Assuming that this timestamp is in milliseconds: GMT: Wed, 01 Jun 2016 04:31:23.256 GMT Your time zone: 01/06/2016, 10:01:23 GMT+5:30
whenToTravel = today = Calendar.getInstance() ;
today.setTime(new Date(System.currentTimeMillis())) ;