Beginner
Beginner

Reputation: 29533

How to get date time stamp in android?

java.text.DateFormat dateFormat = android.text.format.DateFormat.getDateFormat(getApplicationContext());
String date = dateFormat.format(new Date());

Currently i can use this code to get time in dd/mm/yyyy format.

what i would like to get is date and time with no formatting..so for

15/04/2011 12:00:00 i want :

15042011120000

?

Upvotes: 14

Views: 34377

Answers (3)

Ramasamy
Ramasamy

Reputation: 21

Calendar c1 = Calendar.getInstance();      
String myfrmt = c1.get(Calendar.YEAR) + c1.get(Calendar.MONTH) + c1.get(Calendar.DAY_OF_MONTH) + c1.get(Calendar.HOUR_OF_DAY) + c1.get(Calendar.MINUTE);

Upvotes: 2

trojanfoe
trojanfoe

Reputation: 122391

You can create your own DateFormat object (store it statically) and use that in the same way:

dateFormat = new SimpleDateFormat("ddMMyyyyHHmmss");
String date = dateFormat.format(new Date());

Upvotes: 4

Cristian
Cristian

Reputation: 200080

You can use the SimpleDateFormat class:

SimpleDateFormat s = new SimpleDateFormat("ddMMyyyyhhmmss");
String format = s.format(new Date());

Upvotes: 38

Related Questions