DateTime UTC format not accepted by the API

contacts

#1

Hi,
I am trying to post a date field to the HubSpot contact API, however, I am getting errors stating a UTC date is not midnight.

"1505779200 is at 10:16:19.200 UTC, not midnight!"
However, if you use this tool (https://www.epochconverter.com/), and enter that value you will see that the value is midnight.

The c# code I use to do the conversion is:

public static double DateTimeToUTC(System.DateTime dateTime)
{
dateTime = System.DateTime.SpecifyKind(dateTime, DateTimeKind.Utc);
var utcValue = ((DateTimeOffset) dateTime).ToUnixTimeSeconds();
return utcValue;
}
Can anyone help?

Cheers


#2

@mojo Your date/time should be in milliseconds from the epoc. I believe yours is in seconds.


#3

Had the same problem - and the problem was exactly as said @pmanca - the date was in seconds, not in milliseconds. The solution - just add thee zeros (multiply on 1000) to seconds value.


#4

Thanks for the additional clarification Anton!