2014-09-21 35 views
0

我想今天的日期轉換成以下格式爲整數:目標C - 轉換的currentdate整數

年月日

例如2014年9月20日是20140926

下面的代碼工作在高於09代表9變得9無0以外的所有方面如何解決這個問題:

int todaysDate = [[NSString stringWithFormat:@"%d%d%d", (int)currentDate.year, currentDate.month, currentDate.day]integerValue]; 

回答

1
int todaysDate = [[NSString stringWithFormat:@"%d%02d%02d", (int)currentDate.year, currentDate.month, currentDate.day]integerValue]; 

我認爲你也希望當天的領先零。沒有格式化一年。

+0

輝煌 - 謝謝。我是否假設當它變成十月(即10)時,領先的0不會在那裏? – RGriffiths 2014-09-21 18:33:10

+0

@RichardGriffiths - 是的,這是正確的。 – trudyscousin 2014-09-21 18:33:50