开发者

Get Current System Time

开发者 https://www.devze.com 2023-02-13 02:20 出处:网络
How to get Current System\'s Time and Date without using Calende开发者_StackOverflow中文版r.getInstance()?Try this:

How to get Current System's Time and Date without using Calende开发者_StackOverflow中文版r.getInstance()?


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


try

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

You can edit the format string as you like..


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号