In sqlite date difference is coming negative.
SELECT (strftime('%s','now') - strftime('%s', msl_last_sync_date_time))/60/60 as last_synch_time
FROM mobi_sync_log
WHERE my msl_last_sync_date_time is 2015-06-24 10:36:27
Please suggest some idea.
now returns a time in UTC. 2015-06-24 10:36:27 is in the future in UTC considering when you posted the question.
Consider storing all your datetimes in UTC, or add an explicit timezone such as 2015-06-24 10:36:27 +05:30 to them.
Related
I receive a Date String like "2018-06-21T13:30:00Z"
I parse it with the pattern "yyyy-MM-dd'T'HH:mm:ssZ"
I am in GMT+2 and the result looks like 2018-06-21T15:30:00.000+02:00
while i expected it to look like this 2018-06-21T13:30:00.000+02:00
Is the offset supposed to be already applied in the HH:mm:ss part of the Result?
Code
DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ssZ").parseDateTime("2018-06-21T13:30:00Z")
joda:2.9.7
Yes the date time given is in the local time of +02:00.
From ISO 8601 Wikipedia Time offsets from UTC:
The following times all refer to the same moment: "18:30Z", "22:30+04", "1130−0700", and "15:00−03:30". Nautical time zone letters are not used with the exception of Z. To calculate UTC time one has to subtract the offset from the local time, e.g. for "15:00−03:30" do 15:00 − (−03:30) to get 18:30 UTC.
So for your case: 2018-06-21T15:30:00.000+02:00 means 15:30 - 02:00 so a UTC of 13:30
I am stuck on a problem in Firebase where I have would like to:
Check the date and time using the Firebase.ServerValue.TIMESTAMP.
Increment the value of a variable when the date changes.
I have understood how to capture the time and date but how can I know whether the time is 2:00PM of 6 Feb has surpassed and change the value value of the variable after that. Any help would be appreciated.
Convert the date into milliseconds for both for comparison then simply perform a magnitude check.
I want to get the current date as yyyy-MM-dd from SQLite, I use the following query:
***SELECT date('now')***
But instead of returning the current date, it returns the next day from today.
For example, today (2015-12-01) I run the query and it returns (2015-12-02).
What I did wrong?
Image running query + calendar
sqlite date and time functions use UTC time zone internally. In UTC the date was already 2015-12-02.
If you want to use another timezone, you need to specify it explicitly, e.g.
select date('now','-05:00');
I'd suggest to use UTC millisecond timestamps in your database layer though and have the presentation logic such as date formatting with timezone adjustment in your app code.
Reference: https://www.sqlite.org/lang_datefunc.html
This question already has an answer here:
android timezone difference is 1 hour less then expected
(1 answer)
Closed 9 years ago.
I need an offset for "Europe/Russia" to UTC.. in hours. here is my code:
Calendar mCalendar = new GregorianCalendar();
mCalendar.setTimeZone( TimeZone.getTimeZone("Europe/Moscow"));
TimeZone mTimeZone = mCalendar.getTimeZone();
int remote_offset = mTimeZone.getRawOffset()/1000/60/60;
For UTC it should be -4 hours. BUT! some user got 3 hours difference!!
I think, the problem is, Russia doesn't use winter time. And some devices now that, but some not.. how could I implement allway to get "-4" hours?
Regards
First, Russia isn't UTC-4.
The problem has to do with Russia not having daylight saving time. But your issue is probably only happening with android 2.x device and less. The daylight saving time was removed before 4.x as far as I remember (if it's a user input). On the other hand, if you receive a date that was created by the device without user input, you don't have to convert it as it's already as UTC.
But as I said, Russia isn't -4. Russia/Moscow will be +4 hours. But Russia is larger than Moscow really!
Look here: http://en.wikipedia.org/wiki/Time_in_Russia
UTC+03:00 MSK−1: Kaliningrad Time Europe/Kaliningrad
UTC+04:00 MSK: Moscow Time Europe/Moscow, Europe/Volgograd, Europe/Samara
UTC+06:00 MSK+2: Yekaterinburg Time Asia/Yekaterinburg
UTC+07:00 MSK+3: Omsk Time Asia/Omsk, Asia/Novosibirsk, Asia/Novokuznetsk
UTC+08:00 MSK+4: Krasnoyarsk Time Asia/Krasnoyarsk
UTC+09:00 MSK+5: Irkutsk Time Asia/Irkutsk
UTC+10:00 MSK+6: Yakutsk Time Asia/Yakutsk
UTC+11:00 MSK+7: Vladivostok Time Asia/Vladivostok, Asia/Sakhalin
UTC+12:00 MSK+8: Magadan Time Asia/Magadan, Asia/Kamchatka, Asia/Anadyr
So what you'll have to do is to check if we're in winter and that the TimeZone is one of those. If the timezone is one of those, you can add one more hour when you want to show. And remove 1 hour when you want to convert to UTC.
I don't believe it's possible to update the TimeZone on the android phones and that also means that it's not exactly possible to do that unless you find an alternative library for Dates that has timezones built-in and which are updated.
You could subclass the DateObject with the functions that you use to behave just like the old date object, all you'll have to do is to make sure it behaves differently on android2.x and not on android 4.x+.
Also check this: http://www.joda.org/joda-time/
I checked there and I guess it could be usable and less hacky than my suggestion above. The TimeZones are up to date so it could just work for every phone since it shouldn't use the internal timezones. On the other hand, if you have functions that require the Date, it might get tricky.
My suggestion is make sure you use UTC everywhere and use JodaTime to format the date with timezones and to do "datetime" operations. If you make sure that your Java Date never contain a TimeZone other than UTC. It should work.
The System-Time of my Android emulator is correct (currently 13:42). But when i use the datetime('now')-function to set the current time in my SQLite Database, the returned value is wrong (11:42).
Is there another time i need to set to get this working correctly?
The return value of datetime('now') is in UTC.
Try
datetime('now', 'localtime')
datetime('now') will return in GMT UTC - which you probably should do then handle the conversion to your local timezone in the app. If you keep it in UTC in the database, then convert it in your activities, your app will work correctly as the user moves around timezones