I came across this problem when I was building the first multi-platform app at My Day To-Do. I am talking about My Simple Notes which was first out for Android and then I was building it for iOS. It’s a simple app that lets you make notes, with a note text, title and a timestamp. This is a multi-platform app i.e. the iOS, Android and the web versions all use the same database. The issue was the timestamp was being saved as a 64-bit integer and there was no date data consistency when using across these platforms. In this post, I will talk a little bit about my problem with Javascript/Swift date incompatibility as well as present the code for the solution to it.

How does it look?

Have a look at the screenshots for the web, Android and iOS versions. Fyi, the Android/web app are a hybrid app built using Ionic framework (with Angular).

The web version

The Android version

iOS version

p.s. I am well aware of the date format inconsistency between the iOS version when compared to Android and web. Also, I can see the layout or the fonts don’t quite match either but again fixing that is a lower priority right now.

I hope the above screen demonstrates how the date and time values are shown when the note was displayed. Hence during the phase of the iOS app development lifecycle, when I got to the point of saving the data, I noticed something.

Javascript/Swift date incompatibility

I didn’t pick it up at first but after saving about 3 to 5 notes from my iOS device, I casually opened the app on my browser. In it, I saw the notes saved from my iOS device YAY! However after saving a few more notes, I noticed that while the note title and content matched between iOS and web/Android, the date did not. The date actually made no sense which got me thinking? Exactly how was I saving the date on the Android/web side of things? Here’s how

  this.note = {
    title: "",
    addedAt: new Date().getTime(),
    text: ""

This is what that data looks like on our Firebase.Firestore database

On iOS side of things, I was saving the date using Date().timeInervalSince1970 method. On investigating more, I found out more about the Javascript Date.getTime(), here’s an excerpt from MDN web docs about  Date().getTime()

The getTime() method returns the number of milliseconds* since the Unix Epoch.

* JavaScript uses milliseconds as the unit of measurement, whereas Unix Time is in seconds.


Since the Android and web version had already been released the solution had to be the iOS app saving data compitable with those versions. Hence, I created a Date extension in Swift with the following variable and method.

extension Date {
    //time interval in milliseconds since 1970
    var jsGetTimeEquivalent:Int64 {
        return Int64((self.timeIntervalSince1970 * 1000.0).rounded())
    func jsToSwiftTime() -> Double {
        return Double(jsGetTimeEquivalent/1000)

To create a new note, we use

init(title: String, body: String) {
    self.title = title
    self.text = body
    self.addedAt = Double(Date().jsGetTimeEquivalent)        

To display the note, we use

note?.addedAt = Date().jsToSwiftTime()

Like the blog? Subscribe for updates


Anyway, this concludes this short post on maintaining data consistency across multi-platform mobile apps.The solution wasn’t hard at all, it just required that I take a step back and carefully isolate the problem and find a solution. All in all, developing cross-platform apps is fun 🙂 It does present some unexpected and unknown challenges.

Like the blog? Subscribe for updates

As usual, if you find any of my posts useful support me by  buying or even trying one of my apps on the App Store. 


Also, if you can leave a review on the App Store or Google Play Store, that would help too.

Featured on Feedspot

My Day To-Do blog has been featured as one of the top 30 Swift programming blogs on the web 🙂 So checkout Feedspot!

Categories: Javascript


Leave a Reply

Your email address will not be published. Required fields are marked *