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.

2 Answers 2

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;
Sign up to request clarification or add additional context in comments.

1 Comment

Is there no way to do something like this: {{new Date(x.Name.ActualSendTimeStamp * 1000) | date:'dd-MM-yy }}
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.

2 Comments

I am already using xdsoft.net/jqplugins/datetimepicker plugin, which I find better.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.