Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] android – How to parse 13-digit sqlite timestamp

Posted on November 11, 2022 By

Solution 1 :

The sqlite timestamp here is 13 digits, but how can one know its specific date.

You simply drop the 3 digits (the milliseconds) you do do this by dividing by 1000 or by using substring(createTime,1,10)

but this year cannot be obtained

If you want the year then you can use the strftime function with the %Y format String. e.g.

strftime('%Y',createTime/1000,'unixepoch','localtime')

I want to get time like 2022-11-03 15:00:54

What you have works. However it is simpler to use

datetime(createTime/1000,'unixepoch','localtime')

The following demonstrates the above (and also includes part of the official documentation regarding the formatting arguments):-

DROP TABLE IF EXISTS warehouse_inout_log;
CREATE TABLE IF NOT EXISTS warehouse_inout_log (createTime INTEGER);
INSERT INTO warehouse_inout_log VALUES
    (1667458854391),(1667458752768),('1667458752768')
;

/*
The strftime() routine returns the date formatted according to the format string specified as the first argument. The format string supports the most common substitutions found in the strftime() function from the standard C library plus two new substitutions, %f and %J. The following is a complete list of valid strftime() substitutions:

%d      day of month: 00
%f      fractional seconds: SS.SSS
%H      hour: 00-24
%j      day of year: 001-366
%J      Julian day number (fractional)
%m      month: 01-12
%M      minute: 00-59
%s      seconds since 1970-01-01
%S      seconds: 00-59
%w      day of week 0-6 with Sunday==0
%W      week of year: 00-53
%Y      year: 0000-9999
%%      %
*/
SELECT 
    strftime('%Y',createTime/1000,'unixepoch','localtime') AS createYear,
    datetime(createTime/1000,'unixepoch','localtime') AS createDateTime,
    strftime('%Y',substr(createTime,1,10),'unixepoch','localtime') AS createYearV2,
    datetime(substr(createTime,1,10),'unixepoch','localtime') AS createDateTimeV2
FROM warehouse_inout_log
;
DROP TABLE IF EXISTS warehouse_inout_log;

Resulting in:-

enter image description here

Problem :

The sqlite timestamp here is 13 digits, but how can one know its specific date. 1667458854391 should correspond to November 2022, but this year cannot be obtained regardless of interpretation or other conversions. I want to get time like 2022-11-03 15:00:54.

READ  [FIXED] java - What is the proper replacement for ViewModelProviders deprecation?
Powered by Inline Related Posts

This method only works for ten digits
datetime(‘now’,’unixepoch’, ‘localtime’)

This is sqllite timestamp, but product specific model does not know,only know that this timestamp is 13-digit just like these: 1667458854391 1667458752768

I tried to do this but it didn’t feel compliant
datetime(substr(warehouse_inout_log.createTime,1,10),’unixepoch’, ‘localtime’),

Comments

Comment posted by blackapps

And if you remove the last three digits? Nano seconds. Milli seconds. Micro seconds. What is used? How many digits do you want? Did you expect?

Comment posted by blackapps

Tell us which timestamp should 2022-11-03 15:00:54 have if it was like you wanted. Show the code.

Android Tags:android, android-sqlite, sqlite, timestamp

Post navigation

Previous Post: [FIXED] android – LottieAnimationView doesn’t show in my_layout.xml
Next Post: [FIXED] android – Firestore conditional array query

Related Posts

[FIXED] java – Display a transparent view over a camera preview? Android
[FIXED] android – requestFocus() on EditText, dismiss BotSheetDialog w/o hide keyboard and keyboard strangely show up Android
[FIXED] android – Which is better alarm manager or workmanager Android
[FIXED] android – what is the difference between using findViewById() and using directly the id? Android
[FIXED] android – How do I serialize an NLP classification PyTorch model Android
[FIXED] RecyclerViewAdapter in Android Kotlin Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What color are dead flea eggs?
  • What is Indiana vine?
  • What’s the downside of a Chromebook?
  • Is phosphide the same as phosphorus?
  • Why do you need an S bend?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme