I have a string like this: Mon, 07 Jan 2008 17:24:10 GMT
and I want to cinvert it to time_t and send it to localtime function
How can I do it?
How to convert gmt to local time in c/c++?
There are no date string parser functions in the C runtime, there's a fair number of functions that convert in the other direction, but not string to date. This ties to the reason that date inputs are typically so rigid: the number of widely recognized date formats is extreme! Trusting a user to hand-enter a free-form date is unlikely to be very workable.
For Microsoft platforms there is the COleDateTime class, which supports a ParseDateTime method, but I'm uncertain whether or not it supports that specific format -- I suspect not, because the VBScript coercion function CDate doesn't recognize it.
JavaScript/JScript/ECMA Script's Date object's constructor recognizes it, with or without Mon, and with or without the comma, but (unless this is just a homework assignment) you likely already know that.
In any case the unfortunate answer is, you have to do it the hard way, by breaking the string up into its constituents, to obtain numeric inputs to construct the equivalent date value. It's been done 100,000 times if it's been done once -- tell your prof to ease up on the busy work, and get to the good stuff! :-)
Good Luck!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment