Basically I have date format which comes from server and which will be not known before and a date that was already formatted in this format, e.g. the format is "dd/MM/yyyy" and the date is "21/01/2018" (two strings). The format that uses jqx differs from the default JS one, as I can see.
What I need to do is to parse it to JavaScript date object. I couldn't find the answer in the official documentation.
Is there any easy was of parsing the date string if you know the date format, using JS, jqwidgets or momentjs?
Eventually, I've finished with inner jqx method that does that exact thing:
var parsedDate = $.jqx.dataFormat.parsedate(src, format);
Where format in this case is "dd/MM/yyyy" and src is "21/01/2018".
P.S. Thanks for the guy that posted anwer with the code that used $.jqx.dataFormat, that really helped me to find parsedate method.
Related
I need to the date format that is shown in <lastmod></lastmod> tags in sitemap.xml. How can I achieve that?
Output like:
<lastmod>2016-01-21EEST18:01:18+03:00</lastmod>
Where 'EEST' is probably timezone offset.
I have seen this question and the answers in php:
Google Sitemap Date Format
but don't know how to achieve it in Javascript,
Thanks.
EDIT: the question is not duplicate, since I need the correct time format in JavaScript for this.
The lastmod tag uses YYYY-MM-DDThh:mmTZD format, where TZD is the time zone offset. The W3 date and time format gives you 3 options for how to do the TZD: (Z or +hh:mm or -hh:mm)
This means that in javascript you can just use
const date = new Date().toISOString();
and it'll look like 2017-11-15T11:18:17.266Z, which is correct for a sitemap lastmod.
I have a string representing a UTC date:
'2016-07-29T01:33:56.72'
I would like to display this date corrected to my timezone and nicely formatted:
'2016-07-28 22:33:56'
I tried libraries like moment.js or numeral.js but I still didn't found a clear way to do it. My problem so far is that I am starting with a string object and not a Date object.
Answered here for moment.js: How to convert Moment.js date to users local timezone?… – Voyta
I get date value from my source in this format:
02.08.2016 / Day.Month.Year, it's correct.
but JavaScript understand this inverse, Month.Day.Year.
I tried some ways with Moment.js like:
moment('15.08.2016').format('MM.DD.YYYY');
My JsFiddle is: http://jsfiddle.net/PAc3j/389/
There are some results visible, see please output, variable dateThree: Invalid date
My question is, how can I do it with Moment.js or classic JavaScript?
You can specify the format of the input date string like this.
moment('15.08.2016', 'DD.MM.YYYY').format('MM.DD.YYYY');
http://momentjs.com/docs/#/parsing/string-format
I am using the angular.ui DatePicker
http://angular-ui.github.io/bootstrap/#/datepicker
In the doc it says:
"Everything is formatted using the date filter and thus is also localized."
I am having a hard time figuring out how to use the date filter to control the date format set in the model.
Using the DatePicker I am getting a date format set in the model like this:
"2013-09-07T03:18:43.000Z"
However, I am trying to serialize with Grails, and I want my date format to be like this:
"2013-09-07T03:18:43Z"
How do I configure the DatePicker to output this format of date? Or since it is a JavaScript date, do I have to do this at the server side? Ultimately, I would like to send:
"2013-09-07T03:18:43Z"
in a JSON put to the server.
TIA
You can follow this trademark way of parsing the default ISO date format to your own format stripping out the milliseconds, in client side.
Or, in the server side (Grails) you can parse the string to your own format as below:
Date.parse("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "2013-09-07T03:18:43.000Z")
.format("yyyy-MM-dd'T'HH:mm:ss'Z'")
//prints "2013-09-07T03:18:43Z"
If you are persisting a Date instead of a String, just use Date.parse(..) (without .format).
I'm using highcharts for graphical showcase of statistics.
As I understand it,highcharts uses UTC time to parse datetime.In my case,datetime and value both coming from jagged array.When I use only value its fine,when the datetime value enters the case,highcharts does not parse datetime.
I prepared an example here
Datetime in here coming from a string so i must format (dd.MM.yyyy hh:mm:ss)
For this I use moment.js to parse my datetime value.But still no results.
Why highcharts does not render dates properly ?
What is the problem here ?
Thanks
Original code excerpt
var date = moment(graphData.items[i].Date, "dd.MM.yyyy hh:mm:ss");
xdata.push([date._d, graphData.items[i].Value]);
There's a format issue. Instead of "dd.MM.yyyy hh:mm:ss" you should rather use "DD.MM.YYYY hh:mm:ss", as stated in the documentation.
I would also replace the call to the private member _d with a .native() invokation.
Last, but not least, HighCharts excepts to be fed with the number of milliseconds since Epoch. This can be achieved with a call to getTime().
Fixed code
var date = moment(graphData.items[i].Date, "DD.MM.YYYY hh:mm:ss").native();
xdata.push([date.getTime(), graphData.items[i].Value]);
A working patched version of your code is available here.