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      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

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.