开发者

get current time?

开发者 https://www.devze.com 2022-12-29 11:40 出处:网络
How do you get the current time in VC++ CLI 开发者_如何学CVisual Studio 2008,System::DateTime now = System::DateTime::Now;

How do you get the current time in VC++ CLI 开发者_如何学CVisual Studio 2008,


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

(System::DateTime::UtcNow is another alternative)


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

For example:

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


Use the time function from time.h definition and example


EDIT:

Mistook CLI to mean command-line interface, rather than Common Language Infrastructure. Move along, nothing to see 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 a windows specific 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

精彩评论

暂无评论...
验证码 换一张
取 消