Search code examples
swiftdatetimezonensdate

Get the local time of chosen timezone - Swift


I am creating a social media app. You can only post once every 24 hours, and I'm using it with firebase so all of the post' data goes to the firebase database.

When creating a post I have the variable Date, this is how you track if it's been 24 hours since the last post...

The only problem is that the user can just change the clock on their device and post as many times as they want. I need to get a date variable that is the local time of my timezone (EST) so I know that the data is accurate, but I'm not sure how to do it...

This is how I would usually get the current date:

let date = Date()
let currentTime = date.timeIntervalSince1970

So, I just need to get currentTime to be the current Eastern Standard Time (EST)

Thanks in advance!


Solution

  • Get the current timestamp form the firebase server and compare to the date from the last post

    firebase.database.ServerValue.TIMESTAMP
    

    Go here for reference firebase.database

    for firestore

    firebase.firestore.Timestamp.now()
    

    Go here for reference firebase.firestore