当前位置: 动力学知识库 > 问答 > 编程问答 >

android - How to get just the localized TIME as string from a "Date" object?

问题描述:

The title is quite self explanatory.

I realize this might seem trivial and already answered but it is not.

All the answers I found either:

  1. Ask for a format to be specified/hardcoded as "yyyyMMdd HH:mm" (e.g. this answer)

  2. Or they return both date and time (e.g. this).

I need just the time returned from a existing Date object as a string in the user's current locale.

网友答案:

I might be missing something here, but wouldn't the following work?

final DateFormat f = DateFormat.getTimeInstance();
f.format(new Date()));

This outputs e.g.: 10:24:24 AM

Similarly, if you wish to extract only the date, use DateFormat.getDateInstance().

分享给朋友:
您可能感兴趣的文章:
随机阅读: