I’ve been heavily using Android’s calendarview object in a recent Xamrin project, and since Andoird returns the date value of a calendarview in UnixTime (the time in millisecons that has passed since Thursday, 1 January 1970 – UTC), I had to get this back to a valid DateTime.

So I needed a quick way to get DateTime’s from UnixTime, so I’ve been using the following block of code – taken from this Stack Overflow post, and it has been working perfect!

Place this block of code in your project, and pass any UnixTime variables etc. in, to get a valid DateTime back.

The below example takes the returned .Date object from calendarView1 and saves it as a string to my “calTime” string.

Happy Coding!

Share: