Formatting date and time with iPhone SDK?

前端 未结 4 1272
忘掉有多难
忘掉有多难 2020-12-02 10:36

How do I format date and time using iPhone SDK?

For example, how would I extract the date from 9/4/2024 12:00:00 AM to NSDate?

4条回答
  •  甜味超标
    2020-12-02 11:16

    you can format your string using dd/MM/yyyy hh:mm:ss a

    example as below:

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"dd/MM/yyyy hh:mm:ss a"];
    NSLog(@"%@", [dateFormatter dateFromString:@"12/12/2012 12:12:12 AM"]);
    

提交回复
热议问题