问题描述
是否有任何本地化的设施用于执行日期算术
是否正确考虑了闰年,夏令时,以及其他什么
格里高利农历的其他特性? />
具体来说,考虑到以下程序并且它的输出低于
有人可以为time_subtract函数提供合适的主体吗?
Mike
- 8< - program
#include< stdlib.h>
#include< stdio.h>
#include< string.h>
#include< time.h>
time_t *
time_subtract(time_t * timep,struct tm * adj)
{
/ * ???? * /
}
int
main(int argc,char * argv [])
{
struct tm adj;
time_t now;
time_t * time3hoursago;
memset (& adj,0,sizeof adj);
adj.tm_hour = 3; / * 3小时,而不是第3小时* /
now = time(NULL);
time3hoursago = time_subtract(& now,& adj);
puts(ctime(time3hoursago));
返回EXIT_SUCCESS;
}
- 8< - 输出
$ date
Sat Nov 1 02:36:09 EST 2003
$ ./time_sub
Fri Oct 31 23:36:09 2003
Are there any localized facilites for performing date arithmetic that
properly considers leap years, daylight savings time, and whatever
other peculiarities of the gregorian lunar calendar?
Specifically, considering the following program and it''s output below
can someone provide a suitable body for the time_subtract function?
Mike
--8<-- program
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
time_t *
time_subtract(time_t *timep, struct tm *adj)
{
/* ???? */
}
int
main(int argc, char *argv[])
{
struct tm adj;
time_t now;
time_t *time3hoursago;
memset(&adj, 0, sizeof adj);
adj.tm_hour = 3; /* 3 hours, not 3rd hour */
now = time(NULL);
time3hoursago = time_subtract(&now, &adj);
puts(ctime(time3hoursago));
return EXIT_SUCCESS;
}
--8<-- output
$ date
Sat Nov 1 02:36:09 EST 2003
$ ./time_sub
Fri Oct 31 23:36:09 2003
推荐答案
这篇关于日期算术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!