4

I am saving datetime in timestamp string using the following:

date_default_timezone_set('Europe/London'); 
$bdatetime = "31-03-2016 21:52";
            $date = new DateTime($bdatetime);
            $bdatetimeTS = $date->getTimestamp();

which is saving fine. And I can fetch that timestamp and convert it back to its original format using following in angular js:

<td>{{item.bdatetime * 1000 | date:'dd-MM-yy'}}</td>

which is displaying fine all the list of records.

Now I need to edit individual records, in edit form, I have the following field:

<input type="text" ng-model="bdatetime" value="{{bdatetime * 1000 | date:'dd-MM-yy'}}" name="bdatetime" id="datetimepicker" required/>

in JS and binding it using the following:

$scope.bdatetime = data[0].bdatetime;        

which is showing timestamp in input field rather then showing time date in format in the specific format.

I know how to convert timestamp to datetime format for non-bindable.

How can I do this for bindable input field?

This is from string to time stamp but I kind of need a reverse solution from timestamp to input fields.

Community
  • 1
  • 1
Developer
  • 25,073
  • 20
  • 81
  • 128

2 Answers2

2
var timestamp = data[0].bdatetime;
var date = new Date(timestamp * 1000);
var datevalues = ('0' + date.getDate()).slice(-2) + '-' + ('0' + (date.getMonth() + 1)).slice(-2) + '-' + date.getFullYear() + ' ' + date.getHours() + ':' + date.getMinutes();
$scope.bdatetime = datevalues;
Developer
  • 25,073
  • 20
  • 81
  • 128
0

ng-model and value can't be used together. You should use https://github.com/angular-ui/ui-date or write custom directive that handles ngModel controller.

Matjaz Lipus
  • 702
  • 1
  • 5
  • 10
  • I am already using http://xdsoft.net/jqplugins/datetimepicker/ plugin, which I find better. – Developer Feb 10 '14 at 14:23
  • try this http://stackoverflow.com/questions/21549933/jquery-datetime-picker-plugin-does-not-work-with-angularjs-in-ng-view/21607980#21607980 – Matjaz Lipus Feb 10 '14 at 14:35