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 :)
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.
A formatter that converts between dates and their textual representations.
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.
You can get like this
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd/MM/yyyy"
let dateString = dateFormatter.string(from:Date())
print(dateString)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With