Example code of timestamp (or date) to string developed by IOS

Time:2021-10-15

1. Timestamp to string

///Time stamp converted to character 0000-00-00 00:00
+ (NSString *)time_timestampToString:(NSInteger)timestamp{
 NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:timestamp];
 NSDateFormatter *dateFormat=[[NSDateFormatter alloc]init];
  [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm"];
 NSString* string=[dateFormat stringFromDate:confromTimesp];
 return string;
}

1. Date to string

///Date converted to character 0000-00-00 00:00
+ (NSString *)time_dateToString:(NSDate *)date{
 NSDateFormatter *dateFormat=[[NSDateFormatter alloc]init];
 [dateFormat setDateFormat:@"yyyy-MM-dd HH:mm"];
 NSString* string=[dateFormat stringFromDate:date];
 return string;
}

summary

The above is the example code of time stamp (or date) to string conversion of IOS development introduced by Xiaobian. I hope it will help you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time!

Recommended Today

SQL exercise 20 – Modeling & Reporting

This blog is used to review and sort out the common topic modeling architecture, analysis oriented architecture and integration topic reports in data warehouse. I have uploaded these reports to GitHub. If you are interested, you can have a lookAddress:https://github.com/nino-laiqiu/TiTanI recorded a relatively complete development process in my hexo blog deployed on GitHub. You can […]