Quick tip – Set the correct time in Windows Phone 7 emulator

I have been working on building a Windows Phone 7 application that retrieves JSON data from a popular programming community site (Blog post and app source coming soon). I wrote a time span converter and used it to bind the value of the timespan of the occurrence of an event from the current time to a Textblock element in a page in the app. I was surprised to see the converter fail to cast the timespan value to the right format. Debugging through the converter, I found that the current time used for calculation of timespan was 1/08/2010 01:45:23 while the current time was 17/08/2010 23:30:00!

I wanted to make sure DateTime.Now returned the correct value when required. I created a simple single page app for Windows Phone 7, added a button & an event handler for its Click event. The Click event handler formatted the current date & time and set it in the textblock. I compiled & ran the app, clicked on the button and saw the current date to be 01/08/2010 02:02:48 –

I started looking around for clues and recalled the time when I installed the Beta developer tools on the PC I was working on, it was the 1st of August! I started looking for any configuration or settings files that is used by the emulator during the boot process. I ended up finding these files which looked interesting –

I shutdown the emulator, copied out the two files to a safe location and deleted the two files in C:\ProgramData\Microsoft\XDE. I restarted the emulator to see it doing a complete OS boot –

I tried running the test application and found the time was correct –

This seems to a be a bug in the Beta developer tools where the Windows Phone emulator does not pick up the current time from the host operating system or elsewhere. Until the issue is fixed, the workaround is to delete the two saved state files from C:\ProgramData\Microsoft\XDE (Note: The drive letter may be different for your installation) and start the emulator every time you are working with the emulator.

Leave a comment