how to change date format 2021-30-06T05:00:00+07:00 in swift?

edo oktarifa

i want to change date format from 2021-30-06T05:00:00+07:00 to get only time with format hh:mm:ss, but i didn't get it. here is my code i already try

let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
dateFormatter.timeZone = NSTimeZone(name: "GMT+7")
let date = dateFormatter.dateFromString("2021-30-06T05:00:00+07:00")

// change to a readable time format and change to local time zone
dateFormatter.dateFormat = "HH:mm:ss"
dateFormatter.timeZone = NSTimeZone.localTimeZone() 
let timeStamp = dateFormatter.stringFromDate(date!)

print(timeStamp)
Darshan

Your 2021-30-06T05:00:00+07:00 is not matching with yyyy-MM-dd'T'HH:mm:ss.

Date format should be yyyy-dd-MM'T'HH:mm:ssZZZZZ.

let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-dd-MM'T'HH:mm:ssZZZZZ"
let date = dateFormatter.date(from: "2021-30-06T05:00:00+07:00")

// change to a readable time format and change to local time zone
dateFormatter.dateFormat = "HH:mm:ss"
dateFormatter.timeZone = TimeZone.current
let timeStamp = dateFormatter.string(from: date!)
print(timeStamp)

Output:

03:30:00  // This is as per my current timezone.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Java 8 LocalDateTime dropping 00 seconds value when parsing date string value with 00 seconds like "2018-07-06 00:00:00"

Javascript: How to get 2020-05-15T05:00:00Z format date string?

ParseException: Unparseable date: "Wed Mar 30 00:00:00 GMT+05:30 2016" (at offset 4)

How to get date with 00:00:00 timestamp

13-07-2018 00:00 Date Format in store procedure in Oracle

How can I use datetime.strptime on a string in the format '0000-00-00T00:00:00+00:00'?

How can I convert '00: 30: 00 ' format to seconds?

i want to format date ,i have "2019-06-30T23:00:00" this format and i want to display 6/30,so how to format?

How to convert "2019-11-30T07:00:00+09:00" date into integer?

date_format doesn't handle timestamp with `00:00:00`

How to change time format from 1730 to 17:30:00 in R?

In Stata, how can I change the format of a date from "2010-01-11 00:00:00" to "1/11/2010"?

Date format in javascript with time 00:00:00

What is the correct way in C# to parse this date format "Mon Oct 07 00:00:00 EDT 2013"?

how to trim a date to format of 00/00/0000?

How to Convert Date in "01MAR1978:00:00:00" string format to Date Format in SparkR?

How to format elapsedTime start at 00:00:00 instead of the default 07:00:00 in Swift

What is the best way to convert this date format "2019-11-07T13:30:00+05:30" to utc date?

How to format "2021-01-19T12:50:00Z" to: 2021-01-19 12:50:00

How to convert datetime in 2021-05-24T04:44:56+00:00 format?

Format date string 2021-06-13T15:00:00.000Z to how many hours remaining

Date pattrern format of 2021-02-22T00:00:00

Kotlin - Unparseable date: "2021-07-20T12:35:07-07:00"

Error converting '2021-05-30 19:00:00+00' into SQL Server datetime

How to Convert "2021-08-17T20:03:36.480-07:00" to local time in Python?

How to get day/month when i have this string input 2021-07-14T00:00:00.000-0300 in kotlin?

How to convert date like '2021-06-01T11:17:00-07:00' to get date time for particular location (New Delhi) in javascript?

How do I convert this time format into epoch in java? "Tue Dec 28 16:55:00 GMT+05:30 2021" to Epoch

R: Converting date/time format 0000-00-00T00:00:00Z to POSIXct

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  3. 3

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  4. 4

    pump.io port in URL

  5. 5

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    Do Idle Snowflake Connections Use Cloud Services Credits?

  9. 9

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  10. 10

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  11. 11

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  12. 12

    Generate random UUIDv4 with Elm

  13. 13

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  14. 14

    Is it possible to Redo commits removed by GitHub Desktop's Undo on a Mac?

  15. 15

    flutter: dropdown item programmatically unselect problem

  16. 16

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  17. 17

    EXCEL: Find sum of values in one column with criteria from other column

  18. 18

    Pandas - check if dataframe has negative value in any column

  19. 19

    How to use merge windows unallocated space into Ubuntu using GParted?

  20. 20

    Make a B+ Tree concurrent thread safe

  21. 21

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

HotTag

Archive