Check whether specific time has surpassed using Firebase timestamp - android

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.

Related

Sqlite: select ('now') not works as expected

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

Date difference is showing negative value in android

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.

Last Time Contacted

How does android calculate the value for last time contacted. It provides the value in integer format but I am unable to decipher the given value. For example what if I want to compare the two give values to know which contact has been contacted later. Any type of help would be appreciated.
The value you receive is returned in long format and holds the date and time information of the last time called has happened from a particular number.
It returns the milliseconds of that number.
For your reference: http://developer.android.com/reference/android/provider/ContactsContract.ContactOptionsColumns.html#LAST_TIME_CONTACTED
Now how to compute date and time here is the link:
how to convert milliseconds to date format in android?
How to compare:
There are functions "before" and "after" which tells whether the event date is before or after another specified date
Date class: http://developer.android.com/reference/java/util/Date.html#after(java.util.Date)
or
Calendar class: http://developer.android.com/reference/java/util/Calendar.html#after(java.lang.Object)
Depends which one you want to use.
I hope it helps and let me know for more info.
Every time you contact someone, (i.e. make the call Contacts.markAsContacted) the TIMES_CONTACTED should increment by 1 and LAST_TIME_CONTACTED should be updated. However, many device manufacturers have changed this functionality and it is not reliable anymore. There is an open bug for this issue which you could find at
http://code.google.com/p/android/issues/detail?id=8784&q=LAST_TIME_CONTACTED&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars

gps time vs device time

I create a GPS tracking, but when I use DDMS to send coordinate to the emulator and I want to get time of this coordinate through
Date date = new Date(gpsPos.getTime_stamp()); //gpsPos is an obj
gpsPos.setDate_time(date.toString());
The time I got from the function in miliseconds and I converted it to date using date class in java, but the date I got from converted is different from the real date of device.
How can i get the time location equals real time ? any idea? thx
what is the different between date.toString() and date.toGMTString()?
EDIT:
how can we solve it i want my gps time is equal to the real time (logic enough) in order to use it test sth later?
Date(milliSeconds) will create the Date object based on GMT, Date.toString will create a string based on your locale (by default but can be modified). If the milliseconds you used to create the Date object is actually based on your Locale then your time will be off by 4 hours if you're in EDT as an example.

datetime('now') gives wrong time

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

Categories

Resources