獲取系統時間和AMPM

2021-06-06 09:09:24 字數 696 閱讀 7489

這小玩意就不介紹了,直接上**

nsstring* date;

nsdateformatter* formatter = [[nsdateformatteralloc]init];

[formatter

setdateformat

:@"yyyy-mm-dd:hh:mm:ss:zz"];

date = [formatter stringfromdate:[nsdate

date]];

nslog(@"獲取當前

%@",date);

nsdateformatter*formatter1 = [[nsdateformatteralloc] init];

[formatter1 setlocale:[[[nslocalealloc] initwithlocaleidentifier:

@"en_us"

] autorelease]];

[formatter1 setdateformat:@"hh:mm:a"];    

nsstring*ampm = [[[formatter1 stringfromdate:[nsdatedate]] componentsseparatedbystring:

@":"

] objectatindex:2];

nslog(@"獲取上午下午

:%@",ampm);

am,pm時間轉換

最近遇到的乙個問題,在英文作業系統上,獲取到的時間是帶am或者pm的。但是資料庫是datetime型別,儲存的時候竟然都變成0000 00 00 00 00 00.但是在中文作業系統上又是正常的。沒辦法只有轉換了。其實很多時候convert.todatetime 這個方法完全滿足需求。可有些地方確實...

獲取系統時間

include include include include include include sockaddr in標頭檔案 include include include int main int argc,char argv sock fd socket af inet,sock stream...

獲取系統時間

一,如果只是單純的獲取系統時間,用 dateformat如下 dateformat df new dateformat yyyy mm dd hh mm ss string systime df.format new date system.out.println systime 二,如果有 對年,...