Getting Current Time in string in Custom format in objective c

后端 未结 4 1546
无人及你
无人及你 2020-12-12 17:56

I want current time in following format in a string.

dd-mm-yyyy HH:MM

How?

4条回答
  •  独厮守ぢ
    2020-12-12 18:36

    Either use NSDateFormatter as Carl said, or just use good old strftime, which is also perfectly valid Objective-C:

    #import 
    time_t currentTime = time(NULL);
    struct tm timeStruct;
    localtime_r(¤tTime, &timeStruct);
    char buffer[20];
    strftime(buffer, 20, "%d-%m-%Y %H:%M", &timeStruct);
    

提交回复
热议问题