locked
DateTime.Now returning incorrect system datetime RRS feed

  • Question

  • Hi,

    I am using DateTime.Now but it is returning the incorrect date and time.

    The result in the command window is:

    >? DateTime.Now

    {5/2/03 9:21:21 PM}

    Date: {5/2/03 12:00:00 AM}

    dateData: 9855247109664775808

    Day: 2

    DayOfWeek: Friday

    DayOfYear: 122

    Hour: 21

    InternalKind: 9223372036854775808

    InternalTicks: 631875072810000000

    Kind: Local

    Millisecond: 0

    Minute: 21

    Month: 5

    Second: 21

    Ticks: 631875072810000000

    TimeOfDay: {21:21:21}

    Year: 2003

    ...and i ran this at 9.06pm September 15 2006 according to my computer system date.

    Can anyone help me with this.

    Kind Regards,

    Grant.

    Friday, September 15, 2006 9:08 AM

Answers

  • Hi,

    I feel like an idiot :)

    The DateTime.Now method is working correctly - I just didn't even think that it's getting the System Date/Time from my PDA connected through ActiveSync - and I just looked on the PDA and see that the System Date/Time is incorrect on it - which is the time being returned form the DateTime.Now method.

    And an interesting note about the emulator - im not sure what date that would return, but assume the emulator would retreive the computers system date/time? maybe I'll have a look at that later as I sometimes use it for debugging etc.

    Sorry for the waste of time, and thanks for your help.

    Cheers,

    Grant.

    Saturday, September 16, 2006 5:11 AM
  • If you are creating a CF app and trying to get the current datetime value then it is possible that it is returning a bogus value.  Try creating a standard Windows app and see if it works correctly.  Presumably if you were actually debugging against a live handheld it would give you the correct time but while running through the emulator it might not.  Just a guess here.

    Michael Taylor - 9/15/06

    Saturday, September 16, 2006 3:24 AM

All replies

  • Never seen that before.  Are you sure your clock didn't somehow get reset by accident?  My version works correctly.  What happens if you try it in code?

    Michael Taylor - 9/15/06
    Friday, September 15, 2006 1:49 PM
  • Hi Michael,

    The system date/time on my computer is definately correct.

    I actually noticed the incorrect value being returned in my code then tried it in the command window and still incorrect.

    I am developing with the compact framework version 2.0 if that makes any difference, but don't see how.

    I also just installed the .Net framework 3.0 - but again, don't see how this would cause the incorrect value.

    Any help would be much appreciated.

    Thanks,

    Grant.

    Friday, September 15, 2006 11:02 PM
  • If you are creating a CF app and trying to get the current datetime value then it is possible that it is returning a bogus value.  Try creating a standard Windows app and see if it works correctly.  Presumably if you were actually debugging against a live handheld it would give you the correct time but while running through the emulator it might not.  Just a guess here.

    Michael Taylor - 9/15/06

    Saturday, September 16, 2006 3:24 AM
  • Hi,

    I feel like an idiot :)

    The DateTime.Now method is working correctly - I just didn't even think that it's getting the System Date/Time from my PDA connected through ActiveSync - and I just looked on the PDA and see that the System Date/Time is incorrect on it - which is the time being returned form the DateTime.Now method.

    And an interesting note about the emulator - im not sure what date that would return, but assume the emulator would retreive the computers system date/time? maybe I'll have a look at that later as I sometimes use it for debugging etc.

    Sorry for the waste of time, and thanks for your help.

    Cheers,

    Grant.

    Saturday, September 16, 2006 5:11 AM