0

I've found this to get proper timestamp.

Before that, i've found this link with static timestamp :

https://maps.googleapis.com/maps/api/timezone/json?location=44.5406%2C-87.5011&timestamp=1374868635&sensor=false

When i make request to google api, i'm changing only lat/lon. I want to say that this timestamp :

timestamp=1374868635

not looks like first timestamp. Does not look like DateTime.

I want to ask what is the best solution to get timestamp to make calls to google api (see the first link i mention).

Thank you in advance.

Community
  • 1
  • 1
Bob Swager
  • 884
  • 9
  • 25
  • 1
    try following : http://stackoverflow.com/questions/249760/how-to-convert-a-unix-timestamp-to-datetime-and-vice-versa – jdweng Apr 25 '17 at 11:48

2 Answers2

1

I think google maps api is probably using a Unix Timestamp. Here you've got a converter to play. You can use this code to get it:

Int32 timestamp = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;

BTW, the question you are linking has nothing to do with Unix Timestamp,it's just Now formatted.

Community
  • 1
  • 1
Pikoh
  • 7,582
  • 28
  • 53
1

Google API uses Unix Timestamp

timestamp specifies the desired time as seconds since midnight, January 1, 1970 UTC. The Google Maps Time Zone API uses the timestamp to determine whether or not Daylight Savings should be applied. Times before 1970 can be expressed as negative values. source: Google API Timezone

Check www.epochconverter.com

To convert current DateTime to Unix Timestamp, use (requires .NET 4.6):

long unixTimestamp = new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds();

System.DateTimeOffset.ToUnixTimeSeconds

one_mile_run
  • 3,264
  • 4
  • 26
  • 29