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
?
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.
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.
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.
You can use the SimpleDateFormat
class:
SimpleDateFormat s = new SimpleDateFormat("ddMMyyyyhhmmss");
String format = s.format(new Date());
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());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With