Search code examples
sqlitereact-nativensdateconvertersrealm-mobile-platform

Convert NSDate to JS Date object - react-native


I am using this library (https://github.com/andpor/react-native-sqlite-storage) to get my OLD sqlite database and try to convert it to my new structure based on realm.io.

Now I am running into an issue when I get NSDate object from sqlite database and store it into my realm model with date object types.

My response from sqlite is:

{ "ZSTART_DATE" : 525346440, "ZCREATED_DATE" : 525346479.77402 }

And I need to convert this properties to JS date object to store it in realm.

Is there a pattern to convert NSDate into JS Date?

Many thanks for your help!


Solution

  • finally I found a solution for my problem!

    SELECT 
       strftime('%m-%d-%Y %H:%M:%S', ZCREATED_DATE + 978307200, 'unixepoch') AS ZCREATED_DATE
    FROM MY_TABLE