coure2011
coure2011

Reputation: 42454

How to get day and date?

i want to get date in 2 labels like this
Label1:-> Tuesday
Label2:-> 2 June 2010

how can i get this value?

Upvotes: 0

Views: 4066

Answers (4)

Marc Steven
Marc Steven

Reputation: 535

In swift, you can do like that:

    let today = Date()
    let weekdayFormatter = DateFormatter()
    let formatter = DateFormatter()
    formatter.dateFormat = "d MMMM yyyy"
    weekdayFormatter.dateFormat = "EEEE"
    let formattedDate = formatter.string(from: today)
    let weekday = weekdayFormatter.string(from: today)

Upvotes: 0

Mehul Mistri
Mehul Mistri

Reputation: 15147

Hello You can get Day and Date From this code and here weekday give you the day Example: Monday,Tuesday for re

NSDate *today = [NSDate date];
NSDateFormatter *weekdayFormatter = [[[NSDateFormatter alloc] init] autorelease];
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateFormat: @"d MMMM yyyy"];
[weekdayFormatter setFormatterBehavior:NSDateFormatterBehavior10_4];
[weekdayFormatter setDateFormat: @"EEEE"];
NSString *formattedDate = [formatter stringFromDate: today];
NSString *weekday = [weekdayFormatter stringFromDate: today];

Upvotes: 2

Jon Shier
Jon Shier

Reputation: 12770

This code will get you the strings you require to set the labels:

NSDate *today = [NSDate date];
NSDateFormatter *weekdayFormatter = [[[NSDateFormatter alloc] init] autorelease];
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateFormat: @"d MMMM yyyy"];
[weekdayFormatter setDateFormat: @"EEEE"];
NSString *formattedDate = [formatter stringFromDate: today];
NSString *weekday = [weekdayFormatter stringFromDate: today];

The date formatters are controlled through this standard: Unicode Date Formats

Upvotes: 6

Dave DeLong
Dave DeLong

Reputation: 243156

[label1 setText:@"Tuesday"];
[label2 setText:@"2 June 2010"];

Or did you need something different?

Upvotes: 4

Related Questions