I using Django-rest and I want to get month form Datefield in AngularJS.
My code is date = '2014-2-30' and I get month: var x = (new Date (Date.parse (date).getMonth().
But x = 1 and value of year = 114.
I read https://docs.angularjs.org/api/ng/filter/date but I can't do it. Would you give me example?
Django REST Framework should pass dates back to Angular in ISO 8601 format (yyyy-MM-dd), so there shouldn't be an issue parsing it on Angular's side.
{{ obj.date | date:"MMMM" }}
MMMM is the Angular date code for the full month (January-December). You can find other Angular date codes in the date filter documentation.
Related
Usually code like as:
html
<p class="small-grey-text float-left">
{{ product.date-created | date:'MMMM dd, yyyy ' }}
</p>
json
[{"date-created": 1475798400 }]
This is must look as October 07, 2016
Result
January 01, 1970
It looks like you are having the same problem as in this thread. The date pipe format is correct you need to multiply out the date by 1000.
date-created or dateCreated is word of element for JS.
Let me that is like with working - date_created or datecreated
I have date in this format
2016-05-22 08:00:00
I am trying to apply a filter like this
<td>{{ event._source.event_date | date : "dd.MM.y"}}</td>
but this does notthing.
What am I missing?
The date pipe requires the value of type Date. A value of string is currently not supported (but work-in-progress).
You can convert the date using new Date('2016-05-22 08:0:00') (not checked if the format is correct and accepted though)
Angular 1:
Add following function to your scope to get Date object from your string. First it converts your string with date to format YYYY-MM-DDTHH:MM:SS (adding 'T' between YYYY-MM-DD and HH:MM:SS).
$scope.isoDate = function(dateString) {
return new Date(dateString.split(' ').join('T'));
};
Now you can use it:
{{ isoDate(event._source.event_date) | date : "dd.MM.y" }}
See jsfiddle
I am getting date in epoch format from the backend.
updatedOn = 1427171737000 (from backend)
I am using angular filter to display the date.
{{updatedOn | date: "MM/dd/yyyy ' ' h:mma Z" }} ==> it turns to be 2015-03-23 21:35:37 -0700
I would like my output to be displayed in PST format which will be 2015-03-24 04:35:37
Any ideas?
If you are using 1.3+ of AngularJS then you just need to pass in the timezone
{{ date_expression | date : format : timezone}}
https://code.angularjs.org/1.3.15/docs/api/ng/filter/date if you want to read further.
{{updatedOn | date: "MM/dd/yyyy" : 'PST' }}
I making the date format using jquery in the text box.
And want to know how can i select the date in the input box .
How can i set the value of current date format in the phpunit selenium?
try to use the php date function
$startDate = date('Y-m-d');
$endDate = date('Y-m-d', strtotime("+30 days"));
$this->type('name=from_date',$startDate);
$this->type('name=to_date',$endDate);
I am developing Windows Form using vs2010 C#
I have 2 datetime pickers
1 is fromDatePicker and the other is ToDatePicker
I want to validate that the toDate is always after from date are the same day
eg if From:30/8/2010...To:16/8/2010
An error message is showed to user.
You can do comparisons on `DateTimes'
if (toDate < fromDate)
{
MessageBox.Show("To date is before from date");
}
If you're not worried about the time portion then use the Date property:
if (toDate.Date < fromDate.Date)
{
MessageBox.Show("To date is before from date");
}
Can you set a minimumDate property on your toDate control to the date on the fromDate control?