none
time function in Visual C#

    Question

  •  

     

    I have been unable to access system time in Visual C#

     

    The documentation code does not work, and referenceing "coredll.dll" gives an "unable to load dll" message -

    The "GetSystemTime" function is supposed to reside in this dll which is loaded at run-time can cannot be referenced.

     

    There does not seem to be any other way to access the system time in C#.--

    I have referenced the appropriate namespaces without success --

     

    any expeerience in this area??

    Sunday, June 10, 2007 2:58 AM

Answers

  • Try

     

        DateTime saveUtcNow = DateTime.UtcNow;

     

    or

        DateTime saveNow = DateTime.Now;

    Sunday, June 10, 2007 4:15 AM

All replies

  • Try

     

        DateTime saveUtcNow = DateTime.UtcNow;

     

    or

        DateTime saveNow = DateTime.Now;

    Sunday, June 10, 2007 4:15 AM
  •  

    Thanks!

     

    This does work and I am able to get a UTC string constructed from it which was my objective!

     

    The "GetSystemTime" function in the Help menu for Orcas Beta C# does not work -- the code from the example gives the error I

    noted, an doesn't seem to currently have any use.

    Sunday, June 10, 2007 11:24 PM
  • You can use Windows API instead, but it's the more difficult way.

     

     

    Code Snippet

    [DllImport("Kernel32.dll")]

    public static extern void GetSystemTime(SystemTime st);

     

    [StructLayout(LayoutKind.Sequential)]

    public class SystemTime

    {

    public ushort wYear;

    public ushort wMonth;

    public ushort wDayOfWeek;

    public ushort wDay;

    public ushort wHour;

    public ushort wMinute;

    public ushort wSecond;

    public ushort wMilliseconds;

    }

     

     

    Tuesday, September 18, 2007 7:40 AM