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.
Related
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 ?
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')
}])
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");
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);
}
I have a Google Sheets spreadsheet. In Column B, I have a list of strings that are either dates or ranges of dates in the format month/date. For example:
7/26
7/27-7/31
8/1
8/2
8/3-8/5
I want to create an array with the first date on the left and the second date (if any) on the right. If there's no second date, it can be left blank. This is what I want:
[7/26,]
[7/27,7/31]
[8/1,]
[8/2,]
[8/3,8/5]
I've tried:
var r = 'B'
var dateString = sheet.getRange(dateColumns[r] + '1:' + dateColumns[r] + lastRow.toString()).getValues();
var dateArr = Utilities.parseCsv(dateString, '-');
But that just keeps concatenating all values. Also if it's possible to put the output in a date format that would be great too.
This was a funny exercise to play with...
Here is a code that does what you want :
function test(){
convertToDateArray('7/26,7/27-7/31,8/1,8/2,8/3-8/5');
}
function convertToDateArray(inputString){
if(typeof(inputString)=='string'){inputString=inputString.split(',')}; // if input is a string then split it into an array using comma as separator
var data = [];
var datesArray = [];
for(var n in inputString){
if(inputString[n].indexOf('-')==-1){inputString[n]+='-'};// if only 1 field add an empty one
data.push(inputString[n].split('-'));// make it an array
}
Logger.log(data);//check
for(var n in data){
var temp = [];
for(var c in data[n]){
Logger.log('data[n][c] = '+ data[n][c]);
var date = data[n][c]!=''? new Date(2014,Number(data[n][c].split('/')[0])-1,Number(data[n][c].split('/')[1]),0,0,0,0) : '';// create date objects with right values
Logger.log('date = '+date);//check
temp.push(date);
}
datesArray.push(temp);//store output data in an array of arrays, ready to setValues in a SS
}
Logger.log(datesArray);
var sh = SpreadsheetApp.getActive().getActiveSheet();
sh.getRange(1,1,datesArray.length,datesArray[0].length).setValues(datesArray);
}
Logger result for datesArray :
[[Sat Jul 26 00:00:00 GMT+02:00 2014, ], [Sun Jul 27 00:00:00 GMT+02:00 2014, Thu Jul 31 00:00:00 GMT+02:00 2014], [Fri Aug 01 00:00:00 GMT+02:00 2014, ], [Sat Aug 02 00:00:00 GMT+02:00 2014, ], [Sun Aug 03 00:00:00 GMT+02:00 2014, Tue Aug 05 00:00:00 GMT+02:00 2014]]