How to get current time from the system

30 views
Skip to first unread message

guyi...@gmail.com

unread,
Jan 23, 2016, 11:01:58 AM1/23/16
to Protocoder
Hello!!

Recently I have been working on a project in Protocoder and I needed to get the time from my Android system. I am not an expert in JavaScript nor in Android, so it took more than two hours to achieve it. I share this here, expecting it could help anyone ;)

To get the current (Unix/POSIX) time you just need to write this

var Time = java.util.Calendar.getInstance().getTimeInMillis();

or

java.lang.Math.round(Time/1000);

if you don't need millisecond precision.

You can also try

var Time = java.util.Calendar.getInstance().getTime();

or have a look to

http://developer.android.com/reference/java/util/Calendar.html

Hope it helps!!

Reply all
Reply to author
Forward
0 new messages