How do I convert unix timestamps so I can load my date controls on my form?
On the form I am building are fields I am loading with the values from the selected feature. Textboxes and comboboxes are loading beautifully now, but not the dates.
In my troubleshooting I saw in an alert a value like 1521096141 from the date field instead of what should be 03/15/2018 02:42:21. When I try to convert with Date.Parse, it errors out because 1521096141 is not recognized as a date. How can I get around this? Please let me know.
Thanks,
Justin
0
-
Hi Justin
the date is in seconds since 1/1-1970.
The trick is to create a new datetime objekt and ad the number of seconds, and then convert to localtime.
Unixdate=1521096141
startDate = new DateTime(1970,1,1,0,0,0,DateTimeKind.Utc)
newdate = startDate.AddMilliseconds(UnixDate).ToLocalTime()
form.Find(Of DatePickerFormItem)("DatePicker1").InitialDate=newdate0 -
Because I was pulling attributes from the selected feature, I found the trick was to add a query to get just the two date fields by the ObjectID of the selected feature and use that featureset in the next steps. I can't explain why this second featureset was necessary when I already had the initial one, but the next step was to assign the date attribute to an object variable, then cast this object variable to a DateTime variable, and finally assign that variable to
form.Find(Of DatePickerFormItem)("DatePicker2").InitialDate0
Du måste logga in om du vill lämna en kommentar.
Kommentarer
2 kommentarer