秒转换成日期/秒转换成时间格式获取当前时间,日期

来源:互联网 发布:2017数据新闻比赛 编辑:程序博客网 时间:2024/06/11 10:45
//转换成时分秒+ (NSString *)timeFormatted:(int)totalSeconds{        int seconds = totalSeconds % 60;    int minutes = (totalSeconds / 60) % 60;    int hours = totalSeconds / 3600;        return [NSString stringWithFormat:@"%02d:%02d:%02d",hours, minutes, seconds];}//转换成当前时刻+ (NSString *)timeDateFormatted:(int)totalSeconds{    NSDate  *date = [NSDate dateWithTimeIntervalSince1970:totalSeconds];    NSTimeZone *zone = [NSTimeZone systemTimeZone];    NSInteger interval = [zone secondsFromGMTForDate: date];    NSDate *localeDate = [date  dateByAddingTimeInterval: interval];    //NSLog(@"enddate=%@",localeDate);    NSString *dateStr = [NSString stringWithFormat:@"%@",localeDate];    return dateStr;}
+(NSString *)getCurrentDate{    NSDate *currentDate = [NSDate date];//获取当前时间,日期    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];    [dateFormatter setDateFormat:@"YYYY/MM/dd hh:mm:ss SS"];    NSString *dateString = [dateFormatter stringFromDate:currentDate];        return dateString;}



0 0
原创粉丝点击