SORU
11 Aralık 2009, Cuma


NSDate bugün, dün, bu Hafta, geçen Hafta, bu Ay, geçen Ay... değişkenleri

Başlıkları UİTableView. titleForHeaderİnSection eklenmiş olması için bugün NSDate, dün, bu Hafta, geçen Hafta, bu Ay, geçen Ay değişkenlerin karşılaştırması için hazır almak için yapmaya çalışıyorum

İstediğim elle kod tarih için aşağıda 2009-12-11 yapılır

 NSDate *today = [NSDate dateWithString:@"2009-12-11 00:00:00  0000"];
 NSDate *yesterday = [NSDate dateWithString:@"2009-12-10 00:00:00  0000"];
 NSDate *thisWeek = [NSDate dateWithString:@"2009-12-06 00:00:00  0000"];
 NSDate *lastWeek = [NSDate dateWithString:@"2009-11-30 00:00:00  0000"];
 NSDate *thisMonth = [NSDate dateWithString:@"2009-12-01 00:00:00  0000"];
 NSDate *lastMonth = [NSDate dateWithString:@"2009-11-01 00:00:00  0000"];

CEVAP
11 Aralık 2009, Cuma


Date and Time Programming Guide uyarlanmıştır:

// Right now, you can remove the seconds into the day if you want
NSDate *today = [NSDate date];

// All intervals taken from Google
NSDate *yesterday = [today dateByAddingTimeInterval: -86400.0];
NSDate *thisWeek  = [today dateByAddingTimeInterval: -604800.0];
NSDate *lastWeek  = [today dateByAddingTimeInterval: -1209600.0];

// To get the correct number of seconds in each month use NSCalendar
NSDate *thisMonth = [today dateByAddingTimeInterval: -2629743.83];
NSDate *lastMonth = [today dateByAddingTimeInterval: -5259487.66];

Eğer gün, ay, bağlı, doğru, kesin rakam isterseniz NSCalendar bir kullanmalısınız.

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • ELPRESADOR

    ELPRESADOR

    21 HAZİRAN 2008
  • Flohoo

    Flohoo

    12 EYLÜL 2009
  • TV and Lust

    TV and Lust

    26 HAZİRAN 2006