why does strptime (c++) seem to not correctly parse date/time string????
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Ive never used any of these functinons. However, a quick look at a man page of the function seems that strptime creates a time structure, from the given string representation of a time. However, the time struct it creates is still not useful to directly extract the day, etc, out of it. It seems there is another function strftime that has similar specifiers to extract the necessary information and put it in a buffer.
The month and year are correct. Here is the definition of "struct tm" from the man page for "localtime":
Code:
Broken-down time is stored in the structure tm which is
defined in <time.h> as follows:
struct tm {
int tm_sec; /* seconds */
int tm_min; /* minutes */
int tm_hour; /* hours */
int tm_mday; /* day of the month */
int tm_mon; /* month */
int tm_year; /* year */
int tm_wday; /* day of the week */
int tm_yday; /* day in the year */
int tm_isdst; /* daylight saving time */
};
The members of the tm structure are:
tm_sec The number of seconds after the minute, normally in the
range 0 to 59, but can be up to 60 to allow for leap seconds.
tm_min The number of minutes after the hour, in the range 0 to
59.
tm_hour
The number of hours past midnight, in the range 0 to 23.
tm_mday
The day of the month, in the range 1 to 31.
tm_mon The number of months since January, in the range 0 to 11.
tm_year
The number of years since 1900.
tm_wday
The number of days since Sunday, in the range 0 to 6.
tm_yday
The number of days since January 1, in the range 0 to 365.
tm_isdst
A flag that indicates whether daylight saving time is in
effect at the time described. The value is positive if
daylight saving time is in effect, zero if it is not, and
negative if the information is not available.
Note that "tm_mon" is in the range 0 to 11 inclusive (Thus the month 11 in your output) and that "tm_year" starts at 1900 (Thus the year 109 in your output).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.