打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
获取时间 年月日时分秒 星期
-(void)prepareTime{
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *now;
NSDateComponents *comps = [[NSDateComponents alloc] init];
NSInteger unitFlags = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit|NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;
now=[NSDate date];
comps = [calendar components:unitFlags fromDate:now];
NSInteger week = [comps weekday];
NSInteger year=[comps year];
NSInteger month = [comps month];
NSInteger day = [comps day];
NSInteger hour = [comps hour];
NSInteger min = [comps minute];
NSInteger sec = [comps second];
NSString*monthStr;
if (month<10) {
monthStr=[NSString stringWithFormat:@"0%ld",month];
}else
{
monthStr=[NSString stringWithFormat:@"%ld",month];
}
NSString*dayStr;
if (day<10) {
dayStr=[NSString stringWithFormat:@"0%ld",day];
}else
{
dayStr=[NSString stringWithFormat:@"%ld",day];
}
week--;//这个不知怎么当时写的时候需要减一
NSString*weekStr;
switch (week) {
case 1:
{
weekStr=@"周一";
}
break;
case 2:
{
weekStr=@"周二";
}
break;
case 3:
{
weekStr=@"周三";
}
break;
case 4:
{
weekStr=@"周四";
}
break;
case 5:
{
weekStr=@"周五";
}
break;
case 6:
{
weekStr=@"周六";
}
break;
case 7:
{
weekStr=@"周日";
}
break;
default:
break;
}
UILabel*label=[[UILabel alloc]initWithFrame:CGRectMake(0, 160,150, 40)];
label.text=[NSString stringWithFormat:@"%ld/%@/%@ %@",year,monthStr,dayStr,weekStr];
[self addSubview:label];
}
返回当前时间,精确到毫秒
- (NSString *)getTimeNow
{
NSString* date;
NSDateFormatter * formatter = [[NSDateFormatter alloc ] init];
//[formatter setDateFormat:@"YYYY.MM.dd.hh.mm.ss"];
[formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss:SSS"];
date = [formatter stringFromDate:[NSDate date]];
timeNow = [[NSString alloc] initWithFormat:@"%@", date];
NSLog(@"%@", timeNow);
return timeNow;
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
iOS开发之NSString的几条实用技巧
OC 常用数据类型之间的转换
IOS
iOS常用公共方法
iOS开发实用技巧- 身份证的正则校验
ios模仿android屏幕密度控件自动适配
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服