Swift Easy DateTime and String Conversion

Edison Lo
Edison Lo
Oct 31, 2017 · 1 min read

There are a lot of time comes to me to deal with the time. It is not a hard stuff but probably quite confusing at the first few times.

Common case: you receive a time string, and needed to convert it to a Date object for further operation.


The confusion comes at when you JUST PRINT the day, no matter what timezone you specified, it will be use the +0000 time zone. However, everything will be ok when you pass the date to the DateComponents and get the mins, hours, day, month from it.

Check out

for complete Date to String converting functions if you are interested.