有没有办法使用c。
读取BIOS的日期和时间有一个头文件bios.h有一个_bios_timeofday方法,用于获取当前时间如何获取当前日期。
答案 0 :(得分:1)
我不知道bios.h
中返回bios当前日期的任何预定义方法。为此,您可以使用time.h
喜欢这些..
方式1:
#include <stdio.h>
#include <time.h>
void main()
{
char *Day[7] = {
"Sunday" , "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"
};
char *Month[12] = {
"January", "February", "March", "April",
"May", "June", "July", "August",
"September", "October", "November", "December"
};
char *Suffix[] = { "st", "nd", "rd", "th" };
int i = 3;
struct tm *OurT = NULL;
time_t Tval = 0;
Tval = time(NULL);
OurT = localtime(&Tval);
switch( OurT->tm_mday )
{
case 1: case 21: case 31:
i= 0; /* Select "st" */
break;
case 2: case 22:
i = 1; /* Select "nd" */
break;
case 3: case 23:
i = 2; /* Select "rd" */
break;
default:
i = 3; /* Select "th" */
break;
}
printf("\nToday is %s the %d%s %s %d", Day[OurT->tm_wday],
OurT->tm_mday, Suffix[i], Month[OurT->tm_mon], 1900 + OurT->tm_year);
printf("\nThe time is %d : %d : %d",
OurT->tm_hour, OurT->tm_min, OurT->tm_sec );
}
方式2:
#include<stdio.h>
#include<time.h>
int main(void)
{
time_t t;
time(&t);
printf("Todays date and time is : %s",ctime(&t));
return 0;
}
here是关于bios.h和time.h方法的一个很好的教程,有很好的例子。
答案 1 :(得分:0)
从您在自己的链接中发布的示例中无偿扩展。
/* Example for biostime */
#include <stdio.h>
#include <bios.h>
void main ()
{
long ticks;
ticks = biostime (0, 0L);
printf("Ticks since midnight is %d\n", ticks);
printf("The seconds since midnight is %d\n", ticks*18.2);
int allSeconds = ticks*18.2;
int hours = allSeconds / 3600;
int minutes = allSeconds / 60 - hours * 60;
int seconds = allSeconds % 60;
// I like military time, if you don't covert it and add an AM/PM indicator.
printf("The bios time is %02d:%02d:%02d\n", hours, minutes, seconds);
}