日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

ios 如何获得系统时间和日期

發布時間:2025/3/17 windows 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ios 如何获得系统时间和日期 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ???iphone 如何獲得系統時間和日期

?

代碼如下:

?? ? ??

?

?

?

?

?#import?<time.h>

?

1。獲得當前的系統時間和日期

?

?

[cpp]?view plaincopy
  • //獲得系統時間??
  • NSDate?*??senddate=[NSDate?date];??
  • NSDateFormatter??*dateformatter=[[NSDateFormatter?alloc]?init];??
  • [dateformatter?setDateFormat:@"HH:mm"];??
  • NSString?*??locationString=[dateformatter?stringFromDate:senddate];??
  • //[dateformatter?setDateFormat:@"YYYY-MM-dd-HH-mm-ss"];??
  • //NSString?*??morelocationString=[dateformatter?stringFromDate:senddate];??
  • ??
  • //獲得系統日期??
  • NSCalendar??*?cal=[NSCalendar??currentCalendar];??
  • NSUInteger??unitFlags=NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit;??
  • NSDateComponents?*?conponent=?[cal?components:unitFlags?fromDate:senddate];??
  • NSInteger?year=[conponent?year];??
  • NSInteger?month=[conponent?month];??
  • NSInteger?day=[conponent?day];??
  • NSString?*??nsDateString=?[NSString??stringWithFormat:@"%4d年%2d月%2d日",year,month,day];??
  • ??
  • [dateformatter?release];??
  • ?

    ?

    ?

    2。從字符串來獲得NSDate

    ?? ?

    [cpp]?view plaincopy
  • string??strYear="1988";??
  • string??strMonth="09";??
  • string??strDay="18";??
  • string??strHour="5";??
  • string??strMinutes="18";??
  • string??strSec="20";??
  • ??????????????
  • ??????????????
  • ??????????
  • morelocationString=[NSString?stringWithFormat:@"%s-%s-%s-%s-%s-%s",strYear.c_str(),strMonth.c_str(),??
  • ????????????????????????????????strDay.c_str(),strHour.c_str(),strMinutes.c_str(),strSec.c_str()];??
  • ??????????????
  • ??????????????
  • ????????????//根據時間字符串獲得NSDate??
  • ????????????NSDateFormatter??*dateformatter=[[NSDateFormatter?alloc]?init];??
  • ????????????[dateformatter?setDateFormat:@"YYYY-MM-dd-HH-mm-ss"];??
  • ????????????NSDate??*?oldDate=[dateformatter?dateFromString:morelocationString];??
  • ?

    ?

    ?? 通過上面的代碼,獲得了NSDate。

    ?

    3。 從GMT時間,得到本地時間

    ?

    ??

    [cpp]?view plaincopy
  • NSDate??*?oldDate=[dateformatter?dateFromString:morelocationString];??
  • ??????????????
  • ??????????????
  • ????????????NSTimeInterval??timeZoneOffset=[[NSTimeZone?systemTimeZone]?secondsFromGMT];??
  • ????????????NSDate??*?newDate=[oldDate?dateByAddingTimeInterval:timeZoneOffset];??
  • ?

    ?

    ?

    ?

    轉載于:https://www.cnblogs.com/bmate/p/3200713.html

    總結

    以上是生活随笔為你收集整理的ios 如何获得系统时间和日期的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。