Convert Date in Local Timezone
Convert date in local timezone to UTC:
In this tutorial, we will learn how to convert a date in local timezone to date in UTC timezone in swift. We will pass the date to the function (we will create it in this tutorial) and it will return the date converted to UTC timezone. So let us start the tutorial and learn how to convert a date to UTC date in swift.Step1: Create a function named "convertToUTC", which will accept a string parameter and that is the date we want to convert into UTC timezone and returns the converted date in UTC timezone as a string.
Step2: We will create a "DateFormatter" that has a date format "dd-MM-yyyy hh:mm a". You can change this date format as per your requirements.
Converted Date == 16-09-2017 05:30 AM
Final conclusion: In this tutorial, you learned how to convert date in device local timezone to UTC timezone in swift language. You can also download the source code from the link ConvertDateToUTC-Tutorial.zip
Comments
Post a Comment
Thank You.