将月/日转换为一年中的某天 [英] Converting month/day to day of year

查看:158
本文介绍了将月/日转换为一年中的某天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将月份和日期转换为一年中的哪一天?

例如,将2月1日转换为32,其中32表示一年中的第32天.

有一个结构需要成为其中的一部分.结构可能是这样的:

How can I convert month and day to the day of the year?

For example, converting FEBRUARY 1 to 32, with 32 meaning the 32nd day of the year.

There is a struct that needs to be a part of it. The struct could be something like this:

struct person {
  char name[30]
  char month;
  int day;
}

推荐答案

一月,一年中的某天等于一个月中的某天;
对于2月,一年中的某天等于月份中的某天再加上31;
其他所有月份,您都不能不知道say年的状况.

:)
for January, day of year equals day of month;
for February, day of year equals day of month plus 31;
for all other months, you can''t say without knowing the leap year situation.

:)


看看时间管理 [ C中的^ ]函数.struct tm类型具有包含一年中某一天的属性,因此您只需要使用其他函数即可将字符串转换为日期.
Take a look at the Time Management[^] functions in C. The struct tm type has a property containing the day of the year, so you just need to use the other functions to convert from a string to a date.


您正在谈论的是将公历日期转换为儒略日期.

请参阅:在朱利安日期和公历日期之间转换 [
What you''re talking about is converting a Gregorian date to a Julian date.

See: Converting Between Julian Dates and Gregorian Calendar Dates [^]. You can write the equation in C, and then if you want the day of the year, just subtract the julian date of the day in question from the julian date from the 1st of January of the year.


这篇关于将月/日转换为一年中的某天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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