C++ , using strptime and strftime to convert date formats including invalid dates -


am using strptime , strftime convert date 1 format in c++, works fine valid input dates in case of invalid dates can't work.

using mktime 'fixes' or changes dates if there invalid day, automatially changes month well. want convert input date 1 format like

if 12/22/99 , want convert mm/dd/yy dd-mm-yyyy, shall convert 22-12-1999.

if there invalid date, shall emit 00 , keep other things in required format, 12/45/01 (in mm/dd/yy) shall convert 00-12-2001 (in dd/mm/yyyy format since day can't 45), problem strptime, mktime, changes value since tm timestruct works way, there possibility that?

a simple use case can be

convert mm/dd/yy dd-mm-yyyy         03/33/99 -> 00-03-1999 

i tried best strptime changes corresponding month in case of wrong input day. tried putting 00 in case of wrong date, strptime handles 00 differently too, each format, can't work. stuck now.

    ////////////////////////////////////////////     //  wants programming question     // repeat, programming question     /////////////////////////////////////////////           struct tm timestruct = {0};            // can in other supported format            char *in = "80-00-11";           string fromstr("%y-%d-%m ");           string tostr("%d/%m/%y");            char buf[255];            if(strptime(in, fromstr.c_str(), &timestruct) == null ) // invalid date              strftime(buf, sizeof(buf), tostr.c_str(), &timestruct);           puts(buf);    /* problem in case of wrong date supplied date in char *in.   want leave out correct parameters of supplied data,   00/**11/98**, changes **11** other value, problem may have day empty field given in code snippet */ 


Comments

Popular posts from this blog

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -