Reputation: 33238
How to get Current System's Time and Date without using Calender.getInstance()
?
Upvotes: 22
Views: 80126
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
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
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
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