我想在Android中获取当前时间.它应该显示为下午2:30,我想将其存储在数据库中.我搜索了很多.但我不知道该怎么做.我怎样才能做到这一点?
Ahm*_*mad 29
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+1:00"));
Date currentLocalTime = cal.getTime();
DateFormat date = new SimpleDateFormat("HH:mm a");
// you can get seconds by adding "...:ss" to it
date.setTimeZone(TimeZone.getTimeZone("GMT+1:00"));
String localTime = date.format(currentLocalTime);
Run Code Online (Sandbox Code Playgroud)
Fur*_*rqi 10
String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
// textView is the TextView view that should display it
textView.setText(currentDateTimeString);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
61023 次 |
| 最近记录: |