
#include <timeh>
time_t ltime;
time( <ime );
这样就可以了, 下面是示例代码,够详细了吧
// crt_timesc
// compile with: /W3
// 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 <timeh>
#include <stdioh>
#include <sys/typesh>
#include <sys/timebh>
#include <stringh>
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( todaytm_hour >= 12 )
{
strcpy_s( ampm, sizeof(ampm), "PM" );
todaytm_hour -= 12;
}
if( todaytm_hour == 0 ) // Adjust if midnight hour
todaytm_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", tstructmillitm );
printf( "Zone difference in hours from UTC:\t%u\n",
tstructtimezone/60 );
printf( "Time zone name:\t\t\t\t%s\n", _tzname[0] ); //C4996
// Note: _tzname is deprecated; consider using _get_tzname
printf( "Daylight savings:\t\t\t%s\n",
tstructdstflag "YES" : "NO" );
// Make time for noon on Christmas, 1993
if( mktime( &xmas ) != (time_t)-1 )
{
err = asctime_s(timebuf, 26, &xmas);
if (err)
{
printf("asctime_s failed due to an invalid argument");
exit(1);
}
printf( "Christmas\t\t\t\t%s\n", timebuf );
}
// Use time structure to build a customized time string
err = _localtime64_s( &today, <ime );
if (err)
{
printf(" _localtime64_s failed due to invalid arguments");
exit(1);
}
// Use strftime to build a customized time string
strftime( tmpbuf, 128,
"Today is %A, day %d of %B in the year %Y\n", &today );
printf( tmpbuf );
}
您好!
对于问题一:
这个方法的意思是系统当前时间与1970年1月1日0点0分0秒的毫秒差
对于问题二:
下面是实现的方法之一
public static void main(String[] args)
{
Calendar c = CalendargetInstance();
//现在的时间(单位:毫秒)
long nowMills = cgetTimeInMillis();
//第二个参数是设置月的,月是基于0的
//arg list:year,month,day,hour,minute,second
cset(2011, 4, 4, 23, 59, 59);
long setMills = cgetTimeInMillis();
long a=setMills-nowMills;
Systemoutprintln("2011年5月4日距当前时间分钟数:"+a/(601000));
}
希望对你有帮助!
希望可以帮到你:一般引起系统不定期重启和关机的故障主要有下面几个原因: 一首先我们要处理掉一个可能性到"我的电脑按"右键-->属性-->高级-->按下"启动及修复"-->把下面"系统失败"那框框的三个选项取消勾选当把这三个选择取消后能解决大部分人的问题哦 二如果自动关机并出现对话框的话极有可能是病毒解决办法:杀毒 三WINDOWS启动程序出错,果WINDOWS在默认状态下启动时有某个程序运行出现错误,系统会重新启动,新加载出现错误的程序,果启动项内有某个程序的错误比较严重,系统就会不断反复启动。解决办法:在系统启动时按F8,进入安全模式,在控制面板--系统--高级里选取“启动和故障恢复”,最后将“系统失败”栏目下的“自动重新启动”的勾勾去掉 四用光驱或者软驱就死机或者重启更或者是多挂了一个硬盘后就常常断电那可能电源有问题解决方法:更换电源 五现在主板一般都有温度保护控制芯片,防止CPU过热烧毁。有时BIOS内的CPU预警温度设置太低,CPU满负荷运行时温度超过预警温度,系统会自动关闭。当然因机箱散热不好引起CPU温度太高无法稳定运行也会引起系统重启解决办法:在BIOS里将保护温度调至比较适当的温度,加强系统散热 六看某种特定的片子会死机重启后没事十有八九是显卡驱动的问题解决办法:下载最稳定的驱动版本 七运行大型3D游戏或系统进程较多时容易经常引起系统自启,种情况相当普遍多系统都采用双通道,如果两条内存的品质和性能差异较大或本身内存条的电气稳定性满足不了双通道的要求,可能造成系统运行不稳定,当运行较大程序时经常出现故障重启解决办法:在BIOS内尝试将内存的CL值调高一些,比如25的调成3,通道的可适当调低系统的总线速度看看,如果这招不灵多半是要换内存了
# include <stdioh>
# include <timeh>
int main(void)
{
time_t timer = time(NULL);
printf("ctime is %s\n", ctime(&timer));
return 0;
}
time获取时间是1970年1月1日到现在的秒数,ctime将秒数转成时间字符串。
上面用javascript实现的挺不错的。
net中用DateTimeNow()Tostring()获取。
要实现实时更新可以使用timer空间,编写一个事件,一秒钟更新一次,这样就跟自动更新一样了。
不过这样比较适合在winForm中使用。
网页中还是使用javascript代码比较好
以上就是关于求一个C++的获取计算机时间的库函数全部的内容,包括:求一个C++的获取计算机时间的库函数、Java菜鸟问题(与获取计算机系统时间相关)、获取计算机每次开机、关机时间等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)