永发信息网

怎么将一个长整型数字转化成时间

答案:2  悬赏:50  手机版
解决时间 2021-02-28 03:36
怎么将一个长整型数字转化成时间
最佳答案
MSDN的例子,有提到你所需要的格式
// crt_times.c
// compile with: /W1
// This program demonstrates these time and date functions:
// time _ftime ctime_s asctime_s
// _localtime64_s _gmtime64_s mktime _tzset
// _strtime_s _strdate_s strftime
//
// Also the global variable:
// _tzname
//

#include
#include
#include
#include
#include

int main()
{
char tmpbuf[128], timebuf[26], ampm[] = "AM ";
time_t ltime;
struct _timeb tstruct;
struct tm today, gmt, xmas = { 0, 0, 12, 25, 11, 93 };
errno_t err;

// Set time zone from TZ environment variable. If TZ is not set,
// the operating system is queried to obtain the default value
// for the variable.
//
_tzset();

// Display operating system-style date and time.
_strtime_s( tmpbuf, 128 );
printf( "OS time:\t\t\t\t%s\n ", tmpbuf );
_strdate_s( tmpbuf, 128 );
printf( "OS date:\t\t\t\t%s\n ", tmpbuf );

// Get UNIX-style time and display as number and string.
time( <ime );
printf( "Time in seconds since UTC 1/1/70:\t%ld\n ", ltime );
err = ctime_s(timebuf, 26, <ime);
if (err)
{
printf( "ctime_s failed due to an invalid argument. ");
exit(1);
}
printf( "UNIX time and date:\t\t\t%s ", timebuf );

// Display UTC.
err = _gmtime64_s( &gmt, <ime );
if (err)
{
printf( "_gmtime64_s failed due to an invalid argument. ");
}
err = asctime_s(timebuf, 26, &gmt);
if (err)
{
printf( "asctime_s failed due to an invalid argument. ");
exit(1);
}
printf( "Coordinated universal time:\t\t%s ", timebuf );

// Convert to time structure and adjust for PM if necessary.
err = _localtime64_s( &today, <ime );
if (err)
{
printf( "_localtime64_s failed due to an invalid argument. ");
exit(1);
}
if( today.tm_hour > = 12 )
{
strcpy_s( ampm, sizeof(ampm), "PM " );
today.tm_hour -= 12;
}
if( today.tm_hour == 0 ) // Adjust if midnight hour.
today.tm_hour = 12;

// Convert today into an ASCII string
err = asctime_s(timebuf, 26, &today);
if (err)
{
printf( "asctime_s failed due to an invalid argument. ");
exit(1);
}

// Note how pointer addition is used to skip the first 11
// characters and printf is used to trim off terminating
// characters.
//
printf( "12-hour time:\t\t\t\t%.8s %s\n ",
timebuf + 11, ampm );

// Print additional time information.
_ftime( &tstruct ); // C4996
// Note: _ftime is deprecated; consider using _ftime_s instead
printf( "Plus milliseconds:\t\t\t%u\n ", tstruct.millitm );
printf( "Zone difference in hours from UTC:\t%u\n ",
tstruct.timezone/60 );
全部回答
调用date.settime()方法,例如: public static void main(string[] args) { long dl = 12345678l; date date = new date(); date.settime(dl); system.out.println(date); }
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
中信证券如何申购新股请详细一点。谢谢
简单的51单片机C程序设计多少钱
亚山食杂店地址在什么地方,想过去办事
新长安之星倒车后视镜怎么调角度
什么季节泡脚
什么,J罗去拜仁了,什么时候的事
胖女生有人喜欢吗?长的蛮可爱的
为什么抢不到陆金所
【校园文明用语】校园文明用语指的是什么
927商务会所在哪里啊,我有事要去这个地方
南昌华特沥青有限公司这个地址在什么地方,我
在三角形ABC中,若角A等于80度,角C等于20度
星星套装门地址在什么地方,想过去办事,
研磨液残留的脏污如何清洗掉
东冒山怎么去啊,有知道地址的么
推荐资讯
电表上rxd是不是一直发送数据
关于借条的授权转让合同
《春望》表达了作者什么样的思想感情?
丰收园农庄在哪里啊,我有事要去这个地方
韵达NO.134500地址在哪,我要去那里办事
PSP模拟PS?恐龙危机2?游戏和插件问题
任蹉跎是什么意思
兰州糟肉的主料
陆贞传奇六司有哪些!!急急急!!
中国古代人口最多的是哪个朝代?
与男朋友第一个情人节送什么礼物?
9x的平方+6x+1=4 这个方程怎么解
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?