I need to book a vehicle.So i get date.BUt i didnt got the time.Actually i want to book at least 2 hours after current time.also i need to get full time from next day onwards please help me.Iam doing in Ionic framework and AngularJS
Thanks in Advance
var timeNow = new Date().getTime();
var twoHoursIntoFuture = new Date(time + 1000 * 60 * 60 * 2);
the new Date() creates a new date object from current time. getTime() gets the time in milliseconds since January 1st, 1970. Then we just add 2 hours into timeNow (1000 * 60 * 60 * 2 milliseconds) and make a new date object based on that.
Check http://www.w3schools.com/jsref/jsref_obj_date.asp for more date manipulation info.
this.myActualDate = new Date(new Date().getTime() + (3 * 24 * 60 * 60 * 1000)).toISOString().toString().substring(0, 10);
this.myMaxDate = new Date(new Date().getTime() + (368 * 24 * 60 * 60 * 1000)).toISOString();
<ion-datetime displayFormat="YYYY/MM/DD" pickerFormat="YYYY MMMM DDDD" min={{myActualDate}} max={{myMaxDate}} [(ngModel)]="myActualDate"
formControlName="booking_date" class="flex-date" required></ion-datetime>
You can modify this code to perform yours.
If you want to extend three days in actual date then you can edit 365 digit into 368.
It will add three days in your date.
I think it will also work for time.
If you edit hours , minutes and seconds.
Related
This gives me a array of createdAt timestamps like: ['2022-05-22T21:57:45.202Z', '2022-05-22T21:57:45.205Z']
const unpaid = feeStatus.map((date) => {
return date.createdAt;
});
Now i wanna try to filter the array and show only those dates that are older than 14 days:
unpaid.filter(
(test) => new Date().getTime() - test.getTime() / (1000 * 60 * 60 * 24) > 14
);
But im getting this error: Uncaught TypeError: test.getTime is not a function
First of all, the getTime() function is a method of the Date object. So you will need to convert the strings to valid Date objects. e.g. new Date(str), or using a library to handle it, like date-fns.
Secondly, there is a group of brackets missing from your formula. It should be:
(new Date().getTime() - new Date(test)) / (1000 * 60 * 60 * 24) > 14.
References:
Date: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date
Precedence: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#table
You need to cast a string format date to Date to be able to use its prototype methods:
unpaid.filter(
(test) => new Date().getTime() - new Date(test).getTime() / (1000 * 60 * 60 * 24) > 14
);
I have an query sorting by timestamp,
and I need to see only the data within last week
so I did
.dbRef
.where('regTime', '>', new Date( -7 * 24 * 60 * 60 * 1000)
but somehow not filtered by correct results.
anyone knows why?
seem to be less interesting / active programmers or people who like to help in react native,
so for future searchers:
let weekAgo = new Date();
let weekInMilliseconds = -7 * 24 * 60 * 60 * 1000;
weekAgo.setTime(weekAgo.getTime() + weekInMilliseconds);
I want to count how many hours and minutes between two timestamp which are generated by Date.parse. After I get the difference, I need to convert it into hours and minutes like 2.10 (means, 2 hours and 10 minutes). Once I have read that to do it you need to divide it with 3600 so I tried this code but it just gives me 0.89 instead of 1.26.
var now = new Date();
var endTime = Date.parse(now)/1000;
var startTime = Date.parse("2018-03-16 10:29:17")/1000;
$scope.timestamp_difference = startTime - endTime;
$scope.hours = $scope.timestamp_difference/3600;
How to do it right?
In case you haven't heard, Momentjs makes working with dates and times pretty damn easy in javascript i updated code for you may hope it will helps you now
var date1 = moment('03/15/2018 11:00', 'MM/DD/YYYY hh:mm'),
date2 = moment('03/16/2018 10:00', 'MM/DD/YYYY hh:mm');
var duration = moment.duration(date2.diff(date1));
//you will get 23 hours 00 minute
alert(duration.asHours().toFixed(2))
http://jsfiddle.net/dp7rzmw5/9771/
Output: 23:00 hrs
function getTimeDifference(timestampDifference) {
var hours = ~~(timestampDifference / 3600);
var minuts = ~~((timestampDifference - hours * 3600) / 60);
var seconds = timestampDifference - hours * 3600 - minuts * 60;
return hours + '.' + minuts + '.' + seconds;
}
var minutes = "0" + Math.floor(timestampDifference / 60);
// get minutes
var seconds = "0" + Math.floor(timestampDifference - minutes * 60);
// get seconds
var hour = "0" + Math.floor(timestampDifference / 3600);
//get hour
if ( hour > 1 ) {
return hour.substr(-2) + ":" + minutes.substr(-2) + ":" + seconds.substr(-2);
} else {
return minutes.substr(-2) + ":" + seconds.substr(-2);
}
// check if the hour is greater then 1 than return time with hour else return minutes.
I am implementing a function to have a countdown in Angular form current time - existing time in future. If the time has elapsed then display a message. Timer ran out in ..... HH:MM:SS
The end time. Lets call it endTime eg:
9/15/2016 9:16:00 PM
Current time. Time current moment we live.
Lets call it currentTime.
The goal is to get a timer that is Current time - end time. Save it to a Variable TotalHours.
Then calculate the time remaining for NOW to total hours. For example TotalHours = 5. And NOW is 9/14/2016 1:16:00 PM then FinalCountDown = 6:16:00 PM. That is the timer I want running...
Here is how I am doing it...
if (info.endTime) {
var CurrentTime = new Date().toLocaleString('en-US');
moment.locale(); // en
var TotalHours = moment.utc(moment(info.diffTime, "DD/MM/YYYY HH:mm:ss").diff(moment(CurrentTime, "DD/MM/YYYY HH:mm:ss"))).format("HH:mm:ss");
info.finalCountDown= TotalHours;
};
The issue here is the following:
Case 1:
endTime = 9/15/2016 9:16:00 AM
currentTime = 9/15/2016 1:21:00 PM
TotalHours = 4:05:00
But... if its after next 2 days...
Case 2:
endTime = 9/17/2016 9:16:00 AM
currentTime = 9/15/2016 1:21:00 PM
TotalHours = 4:05:00
Total hours is still the same...
I need it to add 24hours + 24 hours + extra time = 48 + 4:05:00 = 52:05:00
also I want it to display as: 52h:05m:00s
Please let me know how to solve this...
A quick and dirty solution would be to simply convert the difference between the two date/time objects to milliseconds and then do some math on the milliseconds and format the output as follows:
var currentTime = new Date("9-15-2016 13:21:00");
var endTime = new Date("9-17-2016 09:16:00");
var ms = (endTime - currentTime); // ms of difference
var days = Math.round(ms/ 86400000);
var hrs = Math.round((ms% 86400000) / 3600000);
var mins = Math.round(((ms% 86400000) % 3600000) / 60000);
$scope.finalCountdown = (days + "d:" + hrs + " h:" + mins + "m left");
You could add in a calculation for the seconds if you needed and you can do some formatting of the numbers to have leading zeros.
However, doing this doesn't account for issues such as leap-years and other data and time anomalies. A better suggestion would be to use angular-moment which utilizes Moment.js as it can handle differences and formatting with ease.
I want to display time duration of a video in silverlight 3.0 application. The format should be like 00:20 / 05:00 . ( Current Video time / Total Video Time). How to get it??.
TimeSpan _duration = mediaElement.NaturalDuration.TimeSpan;
var totalTime = string.Format("{0:00}:{1:00}", (_duration.Hours * 60) + _duration.Minutes, _duration.Seconds);
TimeSpan remaining = _duration.Subtract(mediaElement.Position);
var currentTime = string.Format("{0:00}:{1:00}", (remaining.Hours * 60) + remaining.Minutes, remaining.Seconds);
string result = string.formar("{0}/{1}",totalTime,currentTime);
Try this, Hope this can help.
Regards.