Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 8 - get current date as DD/MM/YYYY

Tags:

date

ios

nsdate

Can anybody give me some code how I get the date?

NSDateComponents *components = [[NSCalendarcurrentCalendar] component:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYearfromDate:[NSDatedate]]; 

NSString *day = [components day]; 
NSString *week = [components month]; 
NSString *year = [components year]; 

NSString *date = [NSString stringWithFormat:@"%@.%@.%@",day,week,year];

^^ my code is not working :S

And is there a way that I can get the date of tomorrow, in 1 week and so on...

Thanks :)

like image 399
Tim Avatar asked Jan 06 '15 01:01

Tim


People also ask

How do I get the current date format in Swift?

print(date) You need to use yyyy . Besides that creating a DateFormatter is "expensive". This will create a new date formatter every time you call this method. Second you should always set the date formatter's locale to "en_US_POSIX" before setting the dateFormat when using a fixed date format.

What is DateFormatter?

A formatter that converts between dates and their textual representations.

How do I get the current date in IOS 4 Swift?

Get current time in “YYYY-MM–DD HH:MM:SS +TIMEZONE” format in Swift. This is the easiest way to show the current date-time.


1 Answers

You can get like this

let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd/MM/yyyy"
let dateString = dateFormatter.string(from:Date())
print(dateString)
like image 87
Ucdemir Avatar answered Sep 17 '22 16:09

Ucdemir