Difference between 'YYYY' and 'yyyy' in NSDateFormatter
Also when using a date format string using the correct format is important.
@"YYYY" is week-based calendar year.
@"yyyy" is ordinary calendar year.
You can go through the whole blog, its a good to give it a look
https://web.archive.org/web/20150423093107/http://realmacsoftware.com/blog/working-with-date-and-time
http://realmacsoftware.com/blog/working-with-date-and-time (dead link)
NSDateFormatter returns nil with format YYYY-MM-ddTHH:mm:ssZ
that would be a better formatter.
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSDateFormatter for datetime
try
"yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ"
The Date Format Patterns guide suggests that "S" is the format specifier for fractions of seconds.
Weird behavior of NSDate, NSDateFormatter
My answer for your question is below
"YYYY" is week-based calendar year.
"yyyy" is ordinary calendar year.
For more details
Difference between 'yyyy' and 'YYYY'
Unicode Standard
NSDateFormatter and stringFromDate
You need to refer to UTC timezone
let dateString = "2016 01 17"
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
dateFormatter.timeZone = NSTimeZone(abbreviation: "UTC")
let s = dateFormatter.dateFromString(dateString)
print(s)
Date formatter not changing properly
The “yyyy” represents the calendar year of the date while the “YYYY” represents the year of the week.
for detail information, please see this Difference between 'YYYY' and 'yyyy' in NSDateFormatter
let getInputString = "2021-03-05T12:21:18"
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
if let getInputDate = dateFormatter.date(from:getInputString){
dateFormatter.dateFormat = "dd-MM-yyyy"
let getoutputString = dateFormatter.string(from: getInputDate)
}
Note : as per @LeoDabus guidelines please ensure the self.Due_Date is empty or not before start the conversion.
Dateformatter returns different dates
Use below dateFormat
instead
df.dateFormat = "MMMM dd, yyyy HH:mm"
Related Topics
Download Array of Images as Byte Array and Convert to Images
Create Tap-Able "Links" in the Nsattributedstring of a Uilabel
Programmatically Get Own Phone Number in Ios
How to Return Value from Alamofire
Making a Uitableview Scroll When Text Field Is Selected
How to Find Specific Subclass of Nsmanagedobject
How to Change Navigation Bar Color in iOS 7
Xcode 4.2 Debug Doesn't Symbolicate Stack Call
How to Center Horizontally Uicollectionview Cells
What Happens When Testflight App Expire
Undefined Symbols For Architecture Armv7
How to Hide Uinavigationbar 1Px Bottom Line
What Is "Constrain to Margin" in Storyboard in Xcode 6