Date: 2021dec30
Language: C/C++
Level: beginner
Q. C/C++: Get the julian date / get the week of the year
A.
The julian date (Nth day of the year) is in the `tm stuct':
#include <time.h>
int JulianDate() {
time_t now = time(NULL);
struct tm here;
localtime_r(&now, &here);
return here.tm_yday;
}
The week of the year is not in there but you can use strftime():
int WeekOfYear() {
time_t now = time(NULL);
struct tm here;
char buf[100];
localtime_r(&now, &here);
strftime(buf, sizeof(buf), "%U", &here);
// Or you may prefer %V
return atoi(buf);
}
int NanosecondsOfEpoc() {
}