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

SOLVED: DateFormater as a stored variable?

Forums > Swift

Now this is displaying with no problem at all. As far is time and day goes, it is fantastic. My problem is that I need to store the getTime as a variable, so that I can save it to Core Data. How can I capture the time as a variable String? I have been postponing this for such along time and I am truly stumped on this issue. I know that it is going to bite me in the pants, when it is going to be so simple? or NO! Again, deeply appriciate any help on this item. robert

Text(getTime())

      .font(.system(size: 45))
     .fontWeight(.heavy)
      .padding(.top,10)

func getTime()->String {

      let format = DateFormatter()
      format.dateFormat = "hh:mm:ss a"
      return format.string(from: Date()) }

2      

Why are you save the Date as a string in CoreData and not as Date?

3      

Damn, you are right. DAH. Time is already built in. I knew tht was going to bite me in the pants. I can't believe on how stupid I feel, as soon as you have said Date.

THANK YOU, robert

2      

Hi Robert,

No worries, Sometimes we all "can not see the wood for the trees". So never feel that, that what this forum is for.

Enjoy your coding

Nigel

2      

Hacking with Swift is sponsored by Essential Developer

SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until April 28th.

Click to save your free spot now

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.