I want to convert ngComboDatePicker date into yyyy-mmm-dd format - angularjs

I am using ngComboDatePicker for date of birth. I am getting date in this format:
dateOfBirth:Wed Jan 03 1940 00:00:00 GMT+0530 (India Standard Time)
this I want to convert into yyyy-mmm-dd format, html.
<ng-combo-date-picker ng-model="user.dateOfBirth" ng-placeholder="YYYY,MMM,DD" ng-min-date="{{ min.toString() }}" ng-max-date="{{ max.toString() }}"></ng-combo-date-picker>.

user.dateOfBirth = $filter('date')(user.dateOfBirth.getTime(), "yyyy-MM-dd");

Related

get Dates In Range in rescript and Daylight Saving Time

i have a calendar in my site which take a start date and end date and pass them into a function who calculates the dates between .
lets sat we have the start date Mon Mar 29 2021 03:00:00 GMT+0300 (Eastern European Summer Time) and the end date is Mon Apr 05 2021 03:00:00 GMT+0300 (Eastern European Summer Time) ; this function should return ["30/3/2021","31/3/2021","1/4/2020","2/4/2020","3/4/2020","4/4/2020"]
let getDatesInRange = (start, end) => {
let dates = ref([])
let current = ref(start)
while current.contents <= end {
dates := dates.contents->Js.Array2.concat([current.contents->toUTCDateString])
current := {
let date = current.contents->toUTCDateString->Js.Date.fromString
date->Js.Date.setDate(date->Js.Date.getDate +. 1.0)->ignore
date
}
}
dates.contents
}
and this is toUTCDateString function which take a date and give the string version of it
let toUTCDateString = date => {
let date = date->External.unSafeCastToJsObject
date["toISOString"]()["split"]("T")[0]
}
These functions where working fine until The time has changed for Daylight Saving Time; we gain an hour so the day stuck there in for some reason
Any body face this issue before and who to deal with such time issues ?

changed original date when changed it on local variable

console.log("pre : "+vm.dailyCheckIn);
console.log(vm.temp_date.setHours(0,0,0,0));
console.log("next : "+vm.dailyCheckIn);
can someone help me with this code.
Result:
before temp variable changed (original date value)
pre : Mon Oct 29 2018 16:37:24 GMT+0530 (India Standard Time)
after temp variable changed (original date value)
next : Mon Oct 29 2018 00:00:00 GMT+0530 (India Standard Time)
It seems like that you have used the same date object in the temporary and in the actual variable. You have to create a new date object for the temporary variable.
e.g
var date = new Date();
var vm = {
dailyCheckIn: date,
temp_date: new Date(date) //Create a new date object
};
console.log("pre : "+vm.dailyCheckIn);
console.log(vm.temp_date.setHours(0,0,0,0));
console.log("next : "+vm.dailyCheckIn);
I hope it will help to you.

Add date format into date regex

I am getting date format like this /Date(1495111091673)/.I have created one custom filter to change date format.
app.filter('jsonDate', function () {
return function (date) {
return new Date(date.match(/\d+/)[0] * 1);
}
})
This filter returns date like this.
Thu May 18 2017 18:08:11 GMT+0530 (India Standard Time)
But I want it as standard format like dd/MM/yyyy so I have edited my filter code like this:
app.filter('jsonDate', function () {
return function (date) {
return new Date(date.match(/\d+/)[0] * 1, 'dd MMMM # HH:mm:ss');
}
})
Is it correct?
This filter returns date like this
Thu May 18 2017 18:08:11 GMT+0530 (India Standard Time)
No it doesn't, that's just how your console (or whatever) is choosing to display the Date instance (via Date.prototype.toString()).
I'd just use AngularJS's date filter ~ https://docs.angularjs.org/api/ng/filter/date.
For example (where dateFormat is your "/Date(1495111091673)/" formatted string)
{{dateFormat | jsonDate | date : 'shortDate'}}
Or in JS
let parsed = $filter('jsonDate')(dateFormat)
let dateString = $filter('date')(parsed, 'shortDate')
or via DI
.controller('controllerName', ['dateFilter', 'jsonDateFilter',
function(dateFilter, jsonDateFilter) {
let dateString = dateFilter(jsonDateFilter(dateFormat), 'shortDate')
}])

Format predefine date into MMM dd yyyy - HH:mm:ss in angular.js

I am getting date like "Tue Jan 19 18:25:08 +0000 2010".
I have to convert above date to MMM dd yyyy - HH:mm:ss or MM dd yyyy - HH:mm:ss format.
I tried and same created a Plunker for the reference. Below is link for the same
Date is formatting correctly but time is not formatting.
https://embed.plnkr.co/2YouE4gQLAuPCOOnvAJF/
I suggest to use moment and angular moment for date related stuff.
In the controller(create a moment object):
$scope.date = moment(<date>, 'ddd MMM DD HH:mm:ss Z YYYY'); //format for Tue Jan 19 18:25:08 +0000 2010
In the view(manipulate the moment object using angular moment):
<p data-ng-bind="date | amDateFormat : 'MMM dd yyyy - HH:mm:ss'"></p>
I always use moment for dates.
$scope.newDate = moment(yourCurrentDate).format('MM DD YYYY HH:mm:ss');
You can use this to convert into timestamp in milliseconds:
$scope.newDate = moment(yourCurrentDate).format('x');
If you want to display a timestamp in milliseconds in any format:
<span>{{newDate | date:'dd/MM/yyyy - hh:mm:ss'}}</span>

Date format issue in Firefox browser

My code
for(n in data.values){
data.values[n].snapshot = new Date(data.values[n].snapshot);
data.values[n].value = parseInt(data.values[n].value);
console.log(data.values[n].snapshot);
}
here console.log shows perfect date in Chrome as 'Thu Aug 07 2014 14:29:00 GMT+0530 (India Standard Time)', but in Firefox it is showing as 'Invalid Date'.
If I console.log(data.values[n].snapshot) before the new Date line, it is showing date as
2014-08-07 14:29
How can I convert the date format to Firefox understandable way.
The Date object only officially accepts two formats:
Mon, 25 Dec 1995 13:30:00 GMT
2011-10-10T14:48:00
This means that your date 2014-08-07 14:29 is invalid.
Your date can be easily made compatible with the second date format though (assuming that date is yyyy-mm-dd hh:mm):
for(n in data.values){
n = n.replace(/\s/g, "T");
data.values[n].snapshot = new Date(data.values[n].snapshot);
data.values[n].value = parseInt(data.values[n].value);
console.log(data.values[n].snapshot);
}

Resources