Niranj Patel
Niranj Patel

Reputation: 33238

Get Current System Time

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

Upvotes: 22

Views: 80126

Answers (4)

user3484328
user3484328

Reputation: 61

You may try this:

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

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

Upvotes: 0

Tushar Vengurlekar
Tushar Vengurlekar

Reputation: 7679

try

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

You can edit the format string as you like..

Upvotes: 25

ryanm
ryanm

Reputation: 3009

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

Upvotes: 2

Harry Joy
Harry Joy

Reputation: 59660

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()

Upvotes: 28

Related Questions