Convert the following date object , which is in string form to normal date format, in controller side.
{"FromDate": "Wed Jan 02 2016 10:56:45 GMT+0530 (India Standard Time)"}
var date = new Date(yourObject.FromDate)
Check for browser compatibility.
Works in Chrome/Firefox.
For Date conversions, you can use moment.js http://momentjs.com/ .
$scope.FromData= "Wed Jan 02 2016 10:56:45 GMT+0530 (India Standard Time)"
{{ $scope.FromDate | date : format : timezone}}
Related
I need to save the timestamp I am getting from database as date object in react. Postgres format of date: timestamp without timezone.
Required format: Sun Dec 01 2019 17:55:25 GMT+0530 (India Standard Time)
I am getting time in this format:
How do I display timezone without GMT-0400 in the string?
So in the image above: I want to display
Wed Aug 30 2017 18:36:49 (EDT)
Thanks!
add a filter after your value such as:
{{value | "EEE MMMM d y HH:mm:ss (Z)" }}
Source: https://docs.angularjs.org/api/ng/filter/date
How can I get the starting time of a particular dateobject in milliseconds? my dateobject is in below format.
Sun Oct 16 2016 21:33:35 GMT+0530 (India Standard Time)
My input
dateobject = Sun Oct 16 2016 21:33:35 GMT+0530 (India Standard Time);
Required Output
Sun Oct 16 2016 00:00:00 GMT+0530 (India Standard Time)
Irrespective of time, I want to get the starting time of this date in milliseconds(i.e Sun Oct 16 2016 00:00:00 GMT+0530 (India Standard Time)?
Sun Oct 16 2016 21:33:35 GMT+0530 (India Standard Time) -> Sun Oct 16 2016 00:00:00 GMT+0530 (India Standard Time)->1476556200000
I tried like this.
var date_form = $filter('dateobject')(toDate, 'yyyy/MM/dd');
(date_form=2016/10/16)
var full_date = new Date($filter('date')(date_form, 'fullDate'));
(full_date = Oct 16 2016 00:00:00 GMT+0530 (India Standard Time))
var milliseconds = full_date.getMilliseconds();
I am not getting the proper output? Is this correct one?
If I'm not wrong, you want to truncate time from date object and want milliseconds values of them.
For truncate time from date object, you don't need any angularJS code, you can do by javascript code only.
First approch
// Truncate time from exists object
toDate.setHours(0);
toDate.setMinutes(0);
toDate.setSeconds(0);
toDate.setMilliseconds(0);
console.log(toDate);
Second approach
// Create new object of date
full_date = new Date(toDate.getFullYear(), toDate.getMonth(), toDate.getDate());
getMilliseconds() method just giving part of milliseconds, its not total milliseconds. use getTime() instance of getMilliseconds() for get milliseconds.
full_date.getTime() // get milliseconds of start date
I want to change date format from Wed Jun 08 2016 05:30:00 GMT+0530 (India Standard Time) to JUN, Wednesday.
I have tried, <p data-ng-bind = "'Wed Jun 08 2016 05:30:00 GMT+0530 (India Standard Time)'| date:'MMM' "></p>
I did not get the exact result(JUN, Wednesday), please help.
Your problem is you're trying to cast a string with date format. So, You need to cast first string to date, then move the hour for the timezone problem, finally apply the filter.
In your controller you must do something like:
# Step 0: Get a date from your string
var date = new Date('Wed Jun 08 2016 05:30:00 GMT+0530');
# Step 1: From the date move, for the Timezones problems.
$scope.date = new Date(date.valueOf() + date.getTimezoneOffset() * 60000);`
Then, in your view you can use {{ date | date:'MMM-EEEE' }}
You can check in this Plnkr: http://plnkr.co/edit/zselhzgL4njIWEXxTWh6?p=preview
I declare my date element in this format in view.
<li>{{dt.Joindate | date:'dd-MM-yyyy'}}</li> //output: Wed Feb 05 2014 15:39:46 GMT+0530 (India Standard Time) comes like this
My data comes as a string,i converted the string date in javascript but the date field does not shows like MM-dd-yyyy
Javascript code:
angular.forEach(response.Data,function(item){
item.Joindate=Date(item.Joindate);
$scope.retrieveddata.push(item);;
});