在我的应用程序中,我使用NSDate
和NSDateformater
以以下格式显示小时:HH:mm
。例如,当我传递代表午夜的时间戳时:1603843200000
我希望将时间设为00:00,而我将获得24:00。我怎样才能将小时设为00:00?
这是我用来格式化时间戳的代码:
NSNumber* timeStamp = currentConsumption.timestamp; // 1603843200000
NSDate* date = [NSDate dateWithTimeIntervalSince1970:([timeStamp longLongValue]/1000)];
NSDateFormatter* df = [NSDateFormatter new];
df.dateFormat = self->graphDateFormat; // @"k:mm"
if(self->graphType == day){
[df setTimeZone:[NSTimeZone timeZoneWithName:@"UTC"]];
}
return [df stringFromDate:date];
答案 0 :(得分:0)
问题是我将格式设置为k:mm
而不是HH:mm
。