2015-08-06 19:37:58
1 /*!2 * < format time and time stamp conversion >3 * 4 * 2015/08/06 by <felove>5 */6#include <stdio.h>7#include <windows.h>8#include <time.h>9 Ten voidTimestamptoformat (time_t& t_1, tm&tm_1); Onetime_t Formattotimestamp (int_nyear,int_nmonth,int_nday,int_nhour,int_nminute,int_nsecond); A - intMain () - { the //time stamp to format time - time_t TIMEP; -Time (&TIMEP); - structTM Tm_1; + Timestamptoformat (timep,tm_1); -printf"Time ():%d\n", TIMEP); +printf"[%04d-%02d-%02d][%02d:%02d:%02d]\n", Tm_1.tm_year +1900, Tm_1.tm_mon +1, tm_1.tm_mday,tm_1.tm_hour,tm_1.tm_min,tm_1.tm_sec); A at //format Time -to-time stamping -time_t timep1 = Formattotimestamp ( -,8,6, -,6,0); -printf"Time ()->localtime ()->mktime ():%d\n", TIMEP1); - -System"Pause"); - return 0; in } - to voidTimestamptoformat (time_t& t_1, tm&tm_1) + { -localtime_s (&tm_1,&t_1); the } * $time_t Formattotimestamp (int_nyear,int_nmonth,int_nday,int_nhour,int_nminute,int_nsecond)Panax Notoginseng { - structTM Tm_1; theTm_1.tm_year = _nyear-1900; +Tm_1.tm_mon = _nmonth-1; ATm_1.tm_mday =_nday; theTm_1.tm_hour =_nhour; +Tm_1.tm_min =_nminute; -Tm_1.tm_sec =_nsecond; $TM_1.TM_ISDST =-1; $time_t timep1 = mktime (&tm_1); - returnTimep1; -}
Format time and time stamp conversions