//
// ViewController.m
// test01
//
// Created by pg on 2017/3/30.
// Copyright © 2017年 vslai. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[NSTimer scheduledTimerWithTimeInterval:0.1 repeats:YES block:^(NSTimer * _Nonnull timer) {
NSString *nowTime = [self getTimeStringForNow];//获取当前时间
NSString *timeStr = [self getTimeStr];//获取当前时间戳
NSLog(@"%@,%@",nowTime,timeStr);
}];
}
- (NSString *)getTimeStr{
NSTimeInterval timeInterval = [[NSDate date] timeIntervalSince1970];
long long nowTime = [[NSNumber numberWithDouble:timeInterval] longLongValue]; // 将double转为long long型
NSString *timeStr = [NSString stringWithFormat:@"%llu",nowTime]; // 输出long long型
return timeStr;
}
- (NSString *)getTimeStringForNow
{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy-MM-dd HH:mm:ss:SSS"]; // 设置日期格式带毫秒格式
NSString *destString = [dateFormat stringFromDate:[NSDate date]];
return destString;
}
@end
Paste_Image.png
网友评论