Get the current time?

How to get the current time in VC ++ CLI Visual Studio 2008,

+2


a source to share


4 answers


System::DateTime now = System::DateTime::Now;

      



( System::DateTime::UtcNow

is another alternative)

+5


a source


You can use the NET System.DateTime.Now property to get the current time. Then you can use the standard DateTime members to get specific information.

For instance:



System::DateTime^ now = System::DateTime::Now;
Console::WriteLine(L"Current hour: {0}", now->Hour);

      

+2


a source


EDIT:

Mistook CLI stands for Command Line Interface, not Common Language Infrastructure. Move on, nothing is visible here.


This should be fairly cross-platform:

#include <stdio.h>
#include <time.h>

void main( )
{
     char dateStr [9];
     char timeStr [9];
     _strdate( dateStr);
     printf( "The current date is %s \n", dateStr);
    _strtime( timeStr );
    printf( "The current time is %s \n", timeStr);
}

      

Alternatively, if you want to use a Windows custom method:

#include <Windows.h>
#include <stdio.h>

void main()
{
    SYSTEMTIME st;
    GetSystemTime(&st);
    printf("Year:%d\nMonth:%d\nDate:%d\nHour:%d\nMin:%d\nSecond:% d\n" ,st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute,st.wSecond);
}

      

Source .

0


a source


Use time function from time.h definition and example

0


a source







All Articles