UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: I would like to extract YYYMMDD from a long date.

Forums > Swift

Hello, I'm messing with dates (I hate messing with dates! :)

As can be seen below I have a date in the format yyyy-MM-dd'T'HH:mm:ss.SSSSZ. I just want YYYMMDDD. I thought I could use dateFormatterToString.dateStyle = .short but this gives me a formatted date YYYY/DD/MM. Not really what I need.

Can anyone advise how I gst simply YYYYMMDD.

Thank you!

// Generate the unformated short date 
        dateFormatterToDate.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSZ"
        if let date = dateFormatterToDate.date(from: isoDate) {
            let dateFormatterToString = DateFormatter()
            dateFormatterToString.dateStyle = .short
            analysisProjects.apDateLaunchedUnformatted[apCrawlNo] = dateFormatterToString .string(from: date)
        }

2      

        dateFormatterToString.dateFormat = "YYYYMMdd"

2      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.