简体   繁体   中英

Convert WebSQL epoch format to Javascript date

I have a Timestamp field in a WebSQL database that is stored like:

/Date(1340420400000)/

When I pull that value out of the db, a literal string is returned to me, and I have to extract the epoch value with a RegEx, parse it as an int, and pass it into a Javascript Date. Is there an easier way to do this, it seems rather clumsy.

I know I could use the SQLLite strftime function, but I'd prefer to use "SELECT *" as I have many large tables and I'd like to avoid identifying each and every field in all my queries.

Thanks!

Chris

If you are so lazy, then you could write

SELECT t.*, strftime('%whatever',t.Timestamp) AS formatted_timestamp
FROM t
...

Or rename the Timestamp column to _Timestamp :

SELECT t.*, strftime('%whatever',t._Timestamp) AS _Timestamp
FROM t
...

Alternatively / additionally you could make a view for every table for selecting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM