Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get date time stamp in android?

Tags:

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

?

like image 764
Beginner Avatar asked Apr 15 '11 14:04

Beginner


People also ask

How do I get a timestamp from a date?

Getting the Current Time Stamp If you instead want to get the current time stamp, you can create a new Date object and use the getTime() method. const currentDate = new Date(); const timestamp = currentDate. getTime(); In JavaScript, a time stamp is the number of milliseconds that have passed since January 1, 1970.

How do I change the timestamp on my Android?

Converting timestamp is really simple to get the formatted date as you want. You just need to create a Calendar object and set your timestamp data on it. Then you got the timestamp data into your calendar object and you can turn it as a string via “DateFormat. format” method.

What is timestamp Android studio?

A Timestamp also provides formatting and parsing operations to support the JDBC escape syntax for timestamp values. The precision of a Timestamp object is calculated to be either: 19 , which is the number of characters in yyyy-mm-dd hh:mm:ss. 20 + s , which is the number of characters in the yyyy-mm-dd hh:mm:ss.


2 Answers

You can use the SimpleDateFormat class:

SimpleDateFormat s = new SimpleDateFormat("ddMMyyyyhhmmss");
String format = s.format(new Date());
like image 176
Cristian Avatar answered Sep 28 '22 08:09

Cristian


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());
like image 30
trojanfoe Avatar answered Sep 28 '22 08:09

trojanfoe