Search code examples
c#datetimegoogle-maps-api-2

Time for request route from Google API


I'm trying to make a request for public transport route to the Google maps API. I must specify a departure time(number of seconds from January 1, 1970). I thought that in C # it is enough to use DateTime.Now.Thick or DateTime.UtcNow.Thick, but ia always get response

"status" : "INVALID_REQUEST"

In the working example from Google indicates the time "1343605500" - I can not understand how I get such a number.


Solution

  • Where did you get .Thick from? That's not a valid property on a Datetime.

    You should do something like:

    DateTime dt = DateTime.UtcNow;
    DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
    int s = (int)(dt - epoch).TotalSeconds;