I've been using a real time flight traffic API lately and I'm stuck at formating the arrival / departure times from a json response.
They come like this:
{
"dep_schd":1426843500,
"arr_schd":1426849800,
"departure":1426844020,
"arrival":1426849221
}
It doesn't look like anything I've seen before. Any ideas on how to make these times readable?
As a bonus, I can give you how an estimated time arrival looks like:
"eta":1426849221
Thank you
Edit:
Okay guys, with a bit more research and the help from you guys I managed to convert my date to a human readable date like this:
var departure = $('#departure');
var departureDate = new Date(json.departure * 1000);
departure.html(departureDate.toUTCString());
Now what I get is something like this:
Fri, 20 Mar 2015 09:33:40 GMT
My question is how can I make it simpler? So as I can get something like this:
Fri, 20 Mar 2015 09:33
This is Unix time. The number of seconds since 01 Jan 1970, 00:00:00 UTC.
On Unix you can use functions like localtime or gmtime and strftime to convert it to a human-readable form. Most languages have similar functions for dealing with these unix timestamps.
To display it in another format, use the "get" functions on the Date object (since it looks like this is JavaScript). For example departure.getUTCHours().
A better solution though is to use a library like moment.js to format the date easily:
var mDeparture = new moment(departureDate);
departure.html(mDeparture.format('YYYY-mm-dd'));
The format which your are displaying is called Epoch and it is then converted into human readable format.Here is a online site where u can get this in readable format http://www.epochconverter.com/
But you didn't mention in which language you want to convert , every language as methods to convert this in human readable and then you have to pick which info you want from it.
Related
I need to convert a string containing a valid UTC time to an Ecto.DateTime one, which I will insert it into my database with the correct format later. I have tried using the Ecto.DateTime.cast(date) method but it doesn't seem to work. The string is Sat Aug 04 11:48:27 +0000 2012 and comes from the Twitter API.
I know there are libraries such as Timex which I didn't inspect yet. Is there any easy working solution already built in Elixir?
There's no built-in solution in Elixir or Erlang for parsing DateTime values of this format:
Sat Aug 04 11:48:27 +0000 2012
You can certainly write a parser yourself, but it's neither going to be short or simple. You'll have to split the string, get the values of both date and time parameters, convert month strings to month integers, parse the timezone, represent the complete value in Elixir/Erlang DateTime formats and then finally cast it to Ecto.DateTime. See the following links:
Elixir Tips - Date Parsing
Erlang - How Can I Parse RFC1123 Dates Into An Erlang Term?
Convert timestamp to datetime in erlang
Using Timex is the best option here.
It's a well written library that allows you to stay away from the chaos of inner workings of Date/Time. With Timex, you can parse your string like this:
"Sat Aug 04 11:48:27 +0000 2012"
|> Timex.parse!("%a %b %d %T %z %Y", :strftime)
|> Ecto.DateTime.cast!
# => #Ecto.DateTime<2012-08-04 11:48:27>
Note: Timex has built-in support for a lot of the common DateTime formats, and I found it weird that a DateTime format being sent by Twitter wasn't supported - so I wrote one for you. Maybe double check to see if your string is correct? Also take a look at Timex Parsing and Formatting documentation.
I'm working on extracting a date from a variable: "curIndex."
Here's what the code looks likes
show(txntime1 <- timestamp(mktdata[curIndex+1L])[,1])
show(txntime <- strftime(txntime1, '%Y-%m-%d %H:%M:%OS6'))
And the output is this:
"##------ Tue Mar 08 14:31:58 2016 ------##"
"NULL"
I'm working within ruleOrderProc of the quantstrat package.
The order time needs to be POSIXlt for the order book. Does anyone know what to do with this funky date format that I'm getting?
If so, thanks!
When all else fails, read the documentation. ;-) ?timestamp says:
The timestamp function writes a timestamp (or other message)
into the history and echos it to the console. On platforms that
do not support a history mechanism only the console message is
printed.
You probably meant to call time or index. Also, the time needs to be POSIXct for the order book, not POSIXlt.
I am brand new (!) to SQLite and will not be studying or using it long-term; however, I am trying to paw through a bit of archived data in a sqlite database using db browser for sqlite.
There is a table with a date field with a value like this: 1435610912000000
Does that make any sense to anyone as to a date of some kind ??
That is the number of microseconds from 1970 (epoch). Therefore, that is 1435610912000 milliseconds (or 1435610912 seconds), which converts to Mon Jun 29 2015 20:48:32 UTC using this website.
This can be a timestamp which every programming language has a function for converting it to a Date objec.
var date = new Date(1435610912000000);
This code above is Javascript that casts the number 1435610912000000 to date
Sat Sep 13 47462 01:53:20 GMT+0100 (WAT)
which is a bit off but the best guess is that it is a timestamp
I am using ColdFusion 10 to make some REST calls and the date returned is using a GMT offset.
Example: 2013-03-25T14:30:40-04:00
I need this formatted for 2 purposes:
Screen Display so it looks something like mm/dd/yyyy hh:mm:ss
To Insert into mySQL.
I have tried a variety of the CF time/date functions but continue to get the "is not a valid date format"
I thought maybe the #ParseDateTime(i.submitted_at,"pop")# would handle it with POP but same issue.
Spent a few hours now trying multiple variations and googling around now just going in circles. Any ideas would be greatly appreciated.
Thanks!
Have a look at the UDF DateConvertISO8601() on CFLib.
DateConvertISO8601(ISO8601dateString, targetZoneOffset) on CFLib
Description:
This function take a string that holds a date in ISO 8601 and converts it to ODBC datetime, but could be adapted to convert to whatever you like. It also will convert to a datetime in a timezone of your choice by specifying the offset, i.e. it could take a datetime in GMT and convert to PT. See http://www.w3.org/TR/NOTE-datetime for description of ISO 8601, the International Standard for the representation of dates and times.
Return Values:
Returns a datetime.
The source code is viewable at the link I provided.
This, 2013-03-25T14:30:40-04:00, is a string. If you run this:
x = left(2013-03-25T14:30:40-04:00, 19);
you get 2013-03-25T14:30:40. You can use the replace function to replace the T with a space. You can then to this
DateTimeVar =parsedatetime('2013-03-25 14:30:40');
Now you have a datetime variable that you can format. If necessary you can do a datediff with the offset from GMT.
This is an informational answer, not a direct answer to the question.
ColdFusion 11 has updated the ParseDateTime() function so that it will correctly convert the ISO-8601 date/time strings to a ColdFusion datetime object.
With a number of remote requests and responses, the date / time values can often be returned in ISO format. In your case, the mask looks like this:
YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)
In this ISO format, the T string is a literal representation of a marker where the time stamp starts in the string (with the offset following directly).
Below is a reusable function that will convert an ISO date format into a useable ColdFusion date time object:
<cffunction name="ISOToDateTime" access="public" returntype="string" output="false"
hint="Converts an ISO 8601 date/time stamp with optional dashes to a ColdFusion
date/time stamp.">
<cfargument name="Date" type="string" required="true" hint="ISO 8601 date/time stamp." />
<cfreturn ARGUMENTS.Date.ReplaceFirst(
"^.*?(\d{4})-?(\d{2})-?(\d{2})T([\d:]+).*$",
"$1-$2-$3 $4"
) />
</cffunction>
You can then call the function like so to output or return a ColdFusion-friendly version of the date time:
ISOToDateTime( "2013-03-25T14:30:40-04:00" )
That function is courtesy of Ben Nadel. The original blog post can be found here:
http://www.bennadel.com/blog/811-Converting-ISO-Date-Time-To-ColdFusion-Date-Time.htm
You can also convert the date time value using the offset, if required. Again, Ben Nadel has a great blog post outlining how to accomplish this:
http://www.bennadel.com/blog/1595-Converting-To-GMT-And-From-GMT-In-ColdFusion-For-Use-With-HTTP-Time-Stamps.htm
CF10 can use this code as stated in the example of the parseDateTime() doc.
<cfset string = "1997-07-16T19:20:30+01:00">
<cfset date = parseDateTime(string, "yyyy-MM-dd'T'HH:mm:ssX")>
As I am trying to plot a few financial time series in Mathematica, I just ran into a problem illustrated in the figure below :
It seems the data are no longer dealt with after Year 2000
Is there a way to fix that ?
What would be the best format to export time series from Bloomberg or Excel to use them in Mathematic (Using version 8).
I do know about the FinancialData function. However, not knowing the exact symbols, it makes it extremely difficult to use Mathematica directly for this.
Why not to use WolframAlpha[...] function - it imports native to Mathematica format and goes up to current dates:
timeseries = WolframAlpha["msft close Jan 1, 2010 to Jan 21 2011",
{{"DateRangeSpecified:Close:FinancialData", 1}, "TimeSeriesData"}];
DateListPlot[timeseries]
That was just an example of input. I am not sure what kind of data you need exactly, but you can get a lot of them via WolframAlpha function. Read this:
1) WolframAlpha
2) Data Formats in Wolfram|Alpha
Use the DateFunction option to tell DateListPlot how to convert dates:
DateFunction -> (DateList[{#, {"MonthNameShort", "YearShort"}}] &)
(The parentheses are important.)
Here's a function to convert those date strings to a format Mathematica can handle better:
dateConv = With[{s = StringSplit[#, "-"]}, {DateList[{s[[2]], "YearShort"}][[1]],
DateList[s[[1]]][[2]]}] &
You can try
DateListPlot[data, DateFunction -> dateConv]
EDIT: Originally I tried DateList[{"Nov-11", {"MonthNameShort", "YearShort"}}] but this tells me String "Nov-
11" cannot be interpreted as a date in format {"MonthNameShort",
"YearShort"}.. Perhaps a bug?