I'm writing a toy logistics service. As a result, products will travel through lots of different timezones, and I'll need to query both the strict ordering of events, as well as what hour of day it is for products (for example, what happened when the sun was at its hottest, at 1200).
At the moment, I'm saving jodatime DateTimes and trying to deal with them exclusively, but I know time is mighty tricky, and I'm wondering if I need to do anything else to make sure it all works.
Given that you're recording events as they occur (rather than planning for future events), you probably don't need to worry about changes to time zone rules which occur in the future.
As such, it would be reasonable to store a timestamp (e.g. as UTC) and also the time zone ID for the location of the event. To make querying easier, you could also store the local time at the time of the event. Just be aware that as a toy is travelling through time zones, there could be multiple events at different instants in time, all of which occur at "midday" on the same day (but in different zones). You really need to think carefully about what queries you really want to perform on the local date/time values.
I am not familiar with jodatime but when I need to store the time I always enjoy using Epoch time because it is very easy to manipulate to get different formats. If you're interested in it here is a converter website that I find very helpful: http://www.epochconverter.com/
I have a datalogger that produces a CSV file containing UTC time and 4 parameters. The UTC time is logged ABOUT every 30ms followed by the 4 parameters. The problem I have is 2 fold:
1) The CSV file is potentially huge if I run the datalogger for even an hour.
2) The UTC time is not exactly every 30ms.
In my simple design for a replay of the data I had planned to load the file, split each entry at character "'" then assign the values in a loop though the UTC time value and then load the 4 parameters, but with the file so large I am concerned it wont work or will be very slow. I am new to java and am not sure if the there is a better way to handle so much data (I suspect there is!).
My plan to loop through and repeat he filling of 4 variables for the parameters wont work as the UTC entries are not exact. I had planned to take a decimal place off the data, but that clearly looses me fidelity in the replay of my data. I want to be able to construct a "timeline" in my application to allow play pause stop style functionality hence my problem handling the UTC time.
Here is a sample of some of the data when the time is pretty tight, this isnt always the case:
,13:35:38.772,0,0,0,0.3515625
,13:35:38.792,0,0,-0.0439453125,0.3515625
,13:35:38.822,0,0,0,0.3515625
,13:35:38.842,0,0,0,0.3515625
,13:35:38.872,0,0,0.0439453125,0.3515625
,13:35:38.892,0,0,0,0.3076171875
,13:35:38.922,0,0,0,0.3076171875
,13:35:38.942,0,0,0,0.3076171875
,13:35:38.962,0,0,0.0439453125,0.3515625
,13:35:38.992,0,0,0,0.3515625
,13:35:39.012,0,0,0,0.3076171875
,13:35:39.042,0,0,-0.0439453125,0.3076171875
,13:35:39.072,0,0,0,0.3515625
,13:35:39.092,0,0,0,0.3515625
,13:35:39.112,0,0,0.0439453125,0.3076171875
,13:35:39.142,0,0,0,0.3515625
,13:35:39.162,0,0,0,0.3076171875
,13:35:39.192,0,0,0,0.3515625
,13:35:39.212,0,0,0,0.3076171875
,13:35:39.242,0,0,0,0.3515625
,13:35:39.262,0,0,0,0.3076171875
I realise this is a broad question, but I am looking for a general steer in how to tackle the problem. Code is welcome, but I am expecting to have to ask more questions as time goes on.
Thanks for the help;
Andy
I am trying to conduct some extremely accurate data measurements. For this, I need to be able to get the current time in microseconds, accurate to 100 microseconds (Or more). I can't seem to be able to find any way on the Android Developer website. Device specific answers are acceptable (I have access to a Nexus 7, so any answers involving that would be awesome).
I had originally thought it possible to use the system sensors which give times accurate to the microsecond, however I have no idea how to set and/or tell if the sensors are accurate. Not to mention whether these event. - SensorManager
Is there any way to get the time in microseconds on an android device that is accurate to within 100microseconds?
you can use System.nanoTime(). according to doc
Returns the current timestamp of the most precise timer available on
the local system. This timestamp can only be used to measure an
elapsed period by comparing it against another timestamp. It cannot be
used as a very exact system time expression.
Returns
the current timestamp in nanoseconds.
From the java doc here you will get some extra explanation of it
I have already a table with three time fields. One to register the hour when the user start working, when stop working and the difference. Now I want to add the day of the week(Mon-Sun) and the date. How can I properly do that, saying that then I will want to grab the hours that the user worked in the past 7 days, lets say.
I've read that timestamp give all the information but I don't know whether I can separate days from date?
**table name = date_time
date_time_id = auto increment
user_id = var
time_in = time
time_out = time
time_dif = time**
ps: I am using java(servlets) and mysql.
Thanks guys
when I start getting really silly with yime in MySql, I use unix time. MySql has built in functions for unix time conversion, too. FROM_UNIXTIME() is one of them. Here's url of a reference page I use.
I've been burned by MySql time (probably more by my own confusion) a few times, so I prefer unix time and then I can manually figure things out by factoring seconds into minutes *60 and hours *60*60 and days *24*60*60.
Change your column types to TIMESTAMP instead of TIME. A timestamp includes both a date and a time.
You should hav column datetime type So you can easily get days month week whatever required.
Here all functions listed you can use as desired with datetime field:
Date and Time Functions
Use org.joda Datetime java library. Its very easy and you can do all the calculations using timestamp.
I currently use a Receiver class which receives my Midi Events from my Midi keyboard.
With each event the send() method returns some information along with the timestamp of the MidiEvent.
When I create a Calendar instance and getTimeInMillis() I get a completely different number to the Receiver's timestamp. The difference of the two values change every time, so I know it's not just a constant value.
Is there a way to get the Receiver's timestamp value at any time without it being through the Receiver's send() method?
By this I mean get a timestamp in a method which follows the same time scale as the Receiver's timestamp.
I believe you may be operating under a misconception - the value of the timestamp Receiver.send() expects is in microseconds, not milliseconds like in Calendar. That means you're off by a factor of 1000, which would appear to be a 'constantly changing value'.
I don't know whether you want to just reduce the resolution of your timestamps, or use the microseconds. It would depend on the exact nature of your application, what data you're getting in your messages, and what you want to do with them.
EDIT:
This is based on the assumption that you're receiving the data, not that you're populating the timestamp value.
If you need to preserve the resolution, here are some options:
Use the java.sql.Timestamp subclass of Date. This can store resolutions down to nanoseconds (more then what you need). However, all of the standard date utilities in the library have some odd behaviour, and the namespace is perhaps less than ideal.
Write your own JRE/JDK/JVM. Calendar and Date are part of the standard library. If you want to distribute your code, you have to expect people to use your version of the standard library. This is inadvisable, for a large number of reasons.
Find/Write your own timestamp-type class. There are probably audio libraries that have a relevant implementation. If you do have to write your own, I'd probably grab the code from Joda Time, and just change the resolution - that would still be a fair bit of work, though.
Just leave the value as the primitive. It's unlikely you need anything more than the numeric values, after all (not like you need to translate to year-month-day values). Although it would be good to have type safety for this, especially in light of the resolution differences. If this doesn't match your use case, I'm sorry.