I'm facing an issue with datetime formatting in angularJS.
I'm trying to convert the datetime "1990-11-25 14:35:00"
into the format 25/11/1990 14:35
, without using a Date
object in the controller.
It seems like angular can only handle proper datetime formatting if the input is a Date
object or lacks hours and minutes.
index.html
<div ng-app ng-controller="Ctrl">
String: {{'1990-11-25 14:35:00' | date:"dd/MM/yyyy HH:mm"}}<br>
string date: {{'1990-11-25' | date:"dd/MM/yyyy"}}<br>
Date: {{myDate | date:"dd/MM/yyyy HH:mm"}}
</div>
controller.js
function Ctrl($scope)
{
$scope.myDate = new Date("1990-11-25 14:35:00");
}
Output
string: 1990-11-25 14:35:00
string date: 25/11/1990
date: 25/11/1990 14:35
http://jsfiddle.net/CkBWL/612/
As per angular's date filter documentation, only certain datetime string formats are supported.
datetime string formats (e.g. yyyy-MM-ddTHH:mm:ss.sssZ and its shorter versions like yyyy-MM-ddTHH:mmZ, yyyy-MM-dd or yyyyMMddTHHmmssZ)
Is there a way to directly format a string like "1990-11-25 14:35:00"
into 25/11/1990 14:35
in the HTML without involving a Date
object?
Thank you for your assistance!