日期算术 [英] Date Arithmetic

查看:63
本文介绍了日期算术的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何本地化的设施用于执行日期算术

是否正确考虑了闰年,夏令时,以及其他什么

格里高利农历的其他特性? />

具体来说,考虑到以下程序并且它的输出低于

有人可以为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

推荐答案

date

11月1日星期六02 :2003年东部时间36:09
date
Sat Nov 1 02:36:09 EST 2003


./ time_sub

Fri Oct 31 23:36:09 2003
./time_sub
Fri Oct 31 23:36:09 2003


" Michael B Allen" < MB ***** @ ioplex.com>在消息中写道

news:pa ********************************** @ ioplex .c om ...
"Michael B Allen" <mb*****@ioplex.com> wrote in message
news:pa**********************************@ioplex.c om...
是否有任何本地化设施用于执行日期算术,以确定正确考虑闰年,夏令时以及格里高利农历的其他特性?

具体来说,考虑到下面的程序,它的输出可以在下面输出
有人为time_subtract函数提供合适的主体吗?

迈克

- 8< - program

#include< stdlib.h>
#include< stdio.h>
#include< string.h> ;
#include< time.h>

time_t *
time_subtract(time_t * timep,struct tm * adj)
{
/ *? ??? * /
time_t t = mktime(adj);

返回difftime(* timep,t)}

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小时* /
现在=时间(NULL);
time3hoursago = time_subtract(& now,& adj);
puts(ctime(time3hoursago));

返回EXIT_SUCCESS;
}
- 8< - 输出

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)
{
/* ???? */ time_t t = mktime(adj);
return difftime(*timep, t) }

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


这篇关于日期算术的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆