Menu
The JavaScript client receives “2014-10-20 18:15:00” from the server. I would like to display it as “10/20/2014 6:15 PM”. I am using the Handlebars JavaScript template, and I know how to create helpers, so I think it is just a JavaScript question.
How is this best accomplished?
Thank you
[CODE]
var $dateFromServer = "2014-10-20 18:15:00"; // The date from the server goes in this string
var $d = new Date(Date.parse(String($dateFromServer.replace(" ", "T"))));
var $s = ($d.getHours() >= 12) ? 'PM' : 'AM';
var $h = ($d.getHours() + 11) % 12 + 1;
var $m = ($d.getMinutes < 10) ? "0" + $d.getMinutes() : $d.getMinutes();
var $newDateFormat = ($d.getMonth()+1) + "/" + $d.getDate() + "/" + $d.getFullYear() + " " + $h + ":" + $m + " " + $s;
console.log($newDateFormat); // Prints "10/20/2014 6:15 PM" out in the console
[/CODE]
The JavaScript client receives "2014-10-20 18:15:00" from the server. I would like to display it as "10/20/2014 6:15 PM". I am using the Handlebars JavaScript template, and I know how to create helpers, so I think it is just a JavaScript question.
How is this best accomplished?
Thank you[/QUOTE]
The thing is I get mixed messages. Some say "the view should perform all formatting, not the model!!!![/QUOTE]
If you have "view" in that stupid malfing "MVC" model being done clientside with scripting, you're probably doing things wrong. Since your server-side code is likely outputting HTML and text, that's part of the view unless you've gone and done something stupid like pissing on accessibility with AJAX and/or providing no graceful degradation.
Generally speaking, I'm [b]NOT[/b] convinced MVC has any business being done with web technologies, because it's not how things like server-side languages or web communication works, nor should it be. I'm all in favor of separating certain things server-side and client-side; like output from processing -- but true MVC?
Sure, it's brilliant in event driven environments like accessing a WM API from languages like C++ or JAVA... but for things like PHP or ASP where you are recieving requests and flat processing them to create markup? That's taking a deuce and a half lump and using it to pound that square peg into a round hole.
Though yeah, you'll have a lot of newly graduated and recent to the field halfwits blindly believing that MVC is great just because they were told so by other nimrods likely not qualified to be opening their mouths on the subject. [i]Sadly, that's true about a LOT of web technologies and how people are using/abusing them ? [/i][/QUOTE]
I've found a template engine like Twig helps[/quote]
I am also not against pissing on accessibility on certain cases.[/quote]
0.1.9 — BETA 5.18