[DateFormat] 시간정보 가져오기

Posted by [하늘이]
2010. 12. 3. 11:32 IT/Android[안드로이드]
반응형

작업하다 보면 시작정보가 필요한 경우가 있다.
파일이름을 시간정보로 저장한다던지...^^
이때 간단히 사용할수 있는 것이 있다.

import java.util.Date;
import android.text.format.DateFormat;

String sTime = DateFormat.format("MM/dd/yy h:mmaa", new Date()).toString();

-------------------------------------------------------------------------
public class

DateFormat

extends Object

This class takes as inputs a format string and a representation of a date/time. The format string controls how the output is generated.

Formatting characters may be repeated in order to get more detailed representations of that field. For instance, the format character 'M' is used to represent the month. Depending on how many times that character is repeated you get a different representation.

For the month of September:
M -> 9
MM -> 09
MMM -> Sep
MMMM -> September

Examples for April 6, 1970 at 3:23am:
"MM/dd/yy h:mmaa" -> "04/06/70 3:23am"
"MMM dd, yyyy h:mmaa" -> "Apr 6, 1970 3:23am"
"MMMM dd, yyyy h:mmaa" -> "April 6, 1970 3:23am"
"E, MMMM dd, yyyy h:mmaa" -> "Mon, April 6, 1970 3:23am&
"EEEE, MMMM dd, yyyy h:mmaa" -> "Monday, April 6, 1970 3:23am"
"'Noteworthy day: 'M/d/yy" -> "Noteworthy day: 4/6/70"

반응형