Timestamp conversion with integer value in milliseconds
- Time stamp converted to time NSDate
- (NSString *) Timewithtimeintervalstring: (NSString *) timestring{//Format time nsdateformatter* formatter = [[NSDateFormatter alloc] init]; formatter.timezone = [nstimezone Timezonewithname:@ "Shanghai"]; [Formatter Setdatestyle:Nsdateformattermediumstyle]; [Formatter Settimestyle:Nsdateformattershortstyle]; [Formatter Setdateformat:@ "yyyy mm month DD day hh:mm"]; //Millisecond value converted to seconds nsdate* date = [nsdate datewithtimeintervalsince1970:[timestring doublevalue]/ 1000.0]; c12>nsstring* datestring = [Formatter stringfromdate:date]; return datestring;}
- Time conversion to timestamp
// 当前时间 NSDate* date = [NSDate dateWithTimeIntervalSinceNow:0]; NSTimeInterval a=[date timeIntervalSince1970]*1000; // *1000 是精确到毫秒,不乘就是精确到秒 NSString *timeString = [NSString stringWithFormat:@"%.0f", a]; //转为字符型
- Method of returning month and day by comparing time with current time
- (void) Getbabydetailage: (NSString *) date{Get Date ObjectNSDateFormatter *formatter_ = [[NSDateFormatter alloc] init]; Formatter_.dateformat =@ "Yyyy-mm-dd HH:mm:ss";nsdate *createdate = [Formatter_ datefromstring:date]; nscalendar *gregorian = [[nscalendar alloc] Initwithcalendaridentifier: nscalendaridentifiergregorian]; nsuinteger unitflags = nscalendarunitday | nscalendarunitmonth | nscalendarunityear; nsdatecomponents *components = [Gregorian components:unitflags fromDate:createDate Todate:[nsdate Date] Options: 0]; nsinteger years = [Components year]; nsinteger months = [Components month]; nsinteger days = [Components day];}
Convert between IOS time and timestamp