0

I have a input field of type "datetime-local" . When I am assigning to it the current TimeStamp, the input filed is showing the seconds and milliseconds also. What is the simplest way to show the time only till minutes ?

  <body ng-controller="MainCtrl">
    <input type="datetime-local" class="form-control" id="DateTime" ng-model="formInfo.dateTime">  
  </body>

The app.js is :

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
   $scope.formInfo = {};
   $scope.formInfo.dateTime = new Date();
});

Here is the Plunker

Karthik
  • 1,447
  • 1
  • 18
  • 26
  • Possible duplicate of [How to format a JavaScript date](http://stackoverflow.com/questions/3552461/how-to-format-a-javascript-date) – christopher Jan 24 '16 at 09:59
  • 1
    why you not use **date** filter see this plunker https://plnkr.co/edit/dVabveNfS8ehyTAOQLMu?p=preview – Sandeep Jan 24 '16 at 16:43
  • @Sandeep, Thanks for information but I want the time also and that too only till minutes. – Karthik Jan 24 '16 at 18:13

3 Answers3

0

Currently, you are using the browser implemented datetime picker. Seeing as this isn't standard across browsers, without using another or having a consistent api for datetime pickers, As far as I know, the datetime input types don't have any options at all associated with them. Below is how you can format a Date() type easily though as I posted it before I noticed you were talking about the display of the browser implemented datetime picker.

Format historical reference

toString().split().slice().join();

This likely isn't as efficient as just formatting it using some of the functions it provides. Its pretty simple though.

var a = (new Date()).toString().split(" ").slice(0,5).join(" ");

document.write(a);
Goblinlord
  • 3,290
  • 1
  • 20
  • 24
  • But we will not be able to simply assign `$scope.formInfo.dateTime = a` – Karthik Jan 24 '16 at 10:15
  • ah yeah... really just display of input is what he wants changed =/... Not sure you can do that considering the datepicker is implemented by the browser used. – Goblinlord Jan 24 '16 at 11:08
0

try using http://momentjs.com/ to formate your model content.

or if you are using angular datepicker https://github.com/g00fy-/angular-datepicker

you already has a directive for formatting date.

<input type="datetime" format="dd MMM yyyy" >
medhatdawoud
  • 1,168
  • 2
  • 12
  • 18
0

Using date filter as suggested by Sandeep in the comments :

  <body  ng-app="plunker" ng-controller="MainCtrl">
    <input type="text" class="form-control" id="DateTime" placeholder="Enter the date and time of consumption" ng-model="formInfo.dateTime| date:'yyyy-MM-dd hh:mm'">
  </body>
Karthik
  • 1,447
  • 1
  • 18
  • 26