admin管理员组文章数量:1352277
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.
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.
Share Improve this question edited May 23, 2017 at 12:19 CommunityBot 11 silver badge asked Feb 10, 2014 at 14:09 DeveloperDeveloper 26.4k20 gold badges84 silver badges132 bronze badges2 Answers
Reset to default 2var 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;
ng-model and value can't be used together. You should use https://github./angular-ui/ui-date or write custom directive that handles ngModel controller.
本文标签: javascriptangularjs timestamp to datetime format string in input fieldStack Overflow
版权声明:本文标题:javascript - angularjs timestamp to datetime format string in input field - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743891113a2556933.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论