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      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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.