I've seen this post already, and it didn't quite shed much light on what is going on.
I have a mongo server, that stores information about classes, what times and days they meet and what not. I also have an express server, that interacts with and returns this data.
When I look at the data in Robo3T (a mongo data viewer), it is formatted - as it should be - like so:
2018-09-07 04:00:00.000Z
But when the data comes back to the server, it comes back like this: 2018-09-07T04:00:00.000Z
What is causing this? In no way do i make any attempt to format this data before I display it. I also checked the server output, which returns it the same way:
I guess my question is, why is this happening? and is this impacting my ability to query results from mongo based on a date range? Any assistance would be much appreciated, thank you.
Robo 3T just happens to display dates that way. This does not mean that it actually is stored that way. When you switch the view to "text mode", you will see that it actually is ISODate("2018-09-07T04:00:00.000Z") (with the T).
This format is actually the date format string that is used in JavaScript. And yes, the T is required. See What are valid Date Time Strings in JavaScript?
Related
I want my users to input date as a string.
The date is passed via a Python backend to a MySQL database where it is stored as datetime.
What is a way of doing this? To clarify, I am asking what kinds of conversions I should do, where, and using what packages.
Now a lot of things in this domain depends on your use-case but I'll take a shot. I'm guessing you pass your data to the server after JSON.stringifying it?
Now we have data on the server. You get everything as json strings, do a json loads and convert them to python strings(unicodes) on your server. From here on, things are easy except for one single problem
You'll have to know the format of your date beforehand
Why?
Because you'll have to do a strptime on your date. A simple example of converting a string date to datetime object is -
from datetime import datetime
dt = datetime.strptime("21/11/06 16:30", "%d/%m/%y %H:%M")
# strptime("date string", "format of date")
The example can be found just below this.
The format table can be found here (which is quite handy, I'd bookmark it)
I hope that makes some if not complete sense
I am trying to understand the data fields in the payload of my remote procedure calls. And Date together with Timestamp type objects confuse me the most.
The full request payload looks like:
7|0|8|https://myapp.com/myapp/client/|72119BCB4CE5FB8D147EA76E8006F76E|com.myapp.service.MyService|updateTimepoint|java.lang.String/2004016611|java.util.Date/3385151746|554455|java.sql.Timestamp/3040052672|1|2|3|4|2|5|6|7|8|VhGcuow|0|
The interface of this service as it is defined in the code is:
public void updateTimepoint(String myId, Date timepoint,
AsyncCallback<Void> async);
From that array of values above, I would tell that bold parts (see below) refer to sent java.util.Date object and "554455" in the middle - is the myId (I know that from the use case). I have no explanation why myId variable was put in the middle:
java.util.Date/3385151746|554455|java.sql.Timestamp/3040052672
Now I'm debugging the obfuscated code, so looking at the Source tab in browser seems like not an option. That won't help a lot though, as you would see weird JS date references. Which I'm not sure how to read either.
So, how would I compile Date+Timestamp from payload vars back into something readable?
Thank you!
P.S. Or - is VhGcuow a Date? As per GWT java.util.Date serialization
As #RobG said, those numbers are not the values, but details about the Date, Timestamp types. The payload is | delimited, those /s are part of the classname string. See Serializing RPC-GWT (an answer by me earlier this year) for more details on the order of the strings and other content in the payload.
VhGcuow is likely a base64-encoded long. Dates (and possibly Timestamps, though I havent checked) are serialized as a long field, so that value as a long would then represent the number of milliseconds since Jan 1, 1970. See RPC-GWT Serialization/java.util.Date Encoding for more discussion on how that can be understood and decoded, without simply trusting that RPC works.
Do note though that RPC hasn't changed in years, and is in use by 10s or 100s of thousands of GWT developers, who havent not had issues with Date serializing correctly. More likely something else is afoot (like timezone issues) - asking another question with all of the details of your problem and a "working" test case might get you to your answer more quickly.
I am new to the world of webdesign and already assigned myself with a very (at least for me) difficult task: I want to build a webpage, that sends a query string to the website of the German Railway (bahn.de) with the parameters I entered on my webpage.
My question now is, if there is a way to decipher the answer, the other webpage (bahn.de) is sending back in regard to my query string.
In my case there will be departure and arrival times, fares, line numbers, .... Is it possible to extract this information from the answer the bahn.de- page is sending?
First and foremost you need to determine what type of data-encoding the website is returning. Is it XML or perhaps JSON? Both formats can be dealt with using a server-side language such as PHP, but the extraction process may differ slightly.
In order to continue along your learning path (which is great, by the way!) you'll need to find out a bit more about what kind of data object the website is sending back from your query. There are plenty of great resources at the other end of a Google search that can teach you how to handle that incoming data once you know which format it is in.
apologies this is probably a simple question - I am using php and JS to create a counter and I have stored a time using an SQL time field in my DB- I run a query to return this time but I now wish to convert this time into an integer, I assume I need to use the following, but I am lost on the syntax:
http://www.electrictoolbox.com/using-strtotime-with-php/
any help would be appreciated. many thanks in advance
It's hard to tell from your question what exactly you mean by "an SQL time field."
MySQL offers four kinds of time-like data types: TIMESTAMP, DATETIME, TIME, and DATE. To some extent it matters which one your table contains.
It's also hard to tell what you mean by "convert this time into an integer." Do you mean a UNIX-style timestamp (number of seconds since 1-Jan-1970 00:00:00 UTC)?
If that's the case you can get your database to do this conversion: use
SELECT UNIX_TIMESTAMP(value) ...
in your query. That will work for all the time-like datatypes except TIME. (Strange, eh? TIME means time of day with no date, so that's why it doesn't work.)
Otherwise, without more information it's hard to tell you how to use php to do this: we can't tell what your converting from and what you're converting to.
I have a strange problem and am unsure on what exactly is causing it and not sure how to fix it in a clever way.
I have a signalR app that sends an object, which contains a date to my client. My client is written in TypeScript, although i am not sure if this has any influence on this or not.
The date in my object is a local date, not UAT.
I need to show the date this way, but when the date arrives in my client it get converted.
It is almost as if the client assumes that the date is UAT and then converts it automatically to local time of the client.
i do not want it to be converted. i just want it displayed as it is.
The one solution i can think of is to convert the date on my server side (c#) to a string first and then send it over like that.
Any better ideas? I don't know if it is signalR that is doing it or it's some sort of std JS behavior. I am really a c# developer and this confuses me completely.
i was also stuck in this datetime issue how i solved is to keep my datetime in UTC in server and let the js handle the conversion and all