1

I am building an android application where I need the TimeStamp but not of local system machine.

What I have done to get TimeStamp used below function.

System.currentTimeMillis()

The problem I was facing in that suppose if the system time is set wrong I will be getting wrong Time in that condition.

Is there any lib. from where I can get current timestamp.

sofquestion 9
  • 167
  • 4
  • 12

3 Answers3

0

May be this can be helpful to you:

Calendar c = Calendar.getInstance(); 
int mseconds = c.get(Calendar.MILLISECOND);
Divya Bhaloidiya
  • 5,018
  • 2
  • 25
  • 45
0

As an alternative you can use

Calendar cal = Calendar.getInstance();
Timestamp time = new Timestamp(cal.getTimeInMillis());

(See this thread for example).

But I don't know what happens when the system time is wrong (can't test it now).

Community
  • 1
  • 1
ThomasThiebaud
  • 11,331
  • 6
  • 54
  • 77
0

If you don't want the system time, you have to get the timestamp from an external resource. This could be your own internet server, a ntp server, you can get a timestamp from gps, ... Have a look at this related question / answer: Network Time from NTP Server

Community
  • 1
  • 1
Florian L.
  • 849
  • 2
  • 8
  • 22
  • I don't want to use any network call to get timestamp – sofquestion 9 Oct 21 '15 at 10:36
  • @sofquestion9 Where else could the timestamp come from? You don't want it from the system (device), then it must come from an external resource which is (without any special hardware) internet or gps. – Florian L. Oct 21 '15 at 11:04