android – Get Current System Time-ThrowExceptions

Exception or error:

How to get Current System’s Time and Date without using Calender.getInstance()?

How to solve:

try

Date d = new Date();
CharSequence s  = DateFormat.format("EEEE, MMMM d, yyyy ", d.getTime());

You can edit the format string as you like..

###

Try this:

//-------- Don't know whether this will work on android or not.
long dtMili = System.currentTimeMillis();
Date dt = new Date(dtMili);

or

new Date().getTime()

###

Constructing a new Date will give the current date. thereafter you can use date.setTime( System.currentTimeMillis() ) to update that object

###

You may try this:

  DateFormat df = DateFormat.getTimeInstance();
  df.setTimeZone(TimeZone.getTimeZone("GMT+05:30"));

  df.format(new Date(System.currentTimeMillis());

Leave a Reply

Your email address will not be published. Required fields are marked *