I am trying to schedule a notification based on a time i am getting from a server.
the problem is the notification shows but its not showing at the right time sometimes it display at the right time and sometimes it doesn't i am not sure why, i think the problem is with the time formatting the one i am getting from the server and the devices time. here an example time i am getting from the server : 2019-12-20T13:55:00.000 now i want to schedule a notification with this time i am doing something like this:
var notifDate = new Date("2019-12-20T13:55:00.000").getTime()
var currentDate = new Date().getTime()
var diff = notifDate - currentDate
Notification.schedule(diff)
now my questions is how can i ensure every notification is gonna display at the right time and maybe if i have to make the currentDate and notifDate the same format. i don't know much about how Date works. i know this question doesnt state much but anykind of suggestion is appreciated.
Thanks
Related
I have a chromecast sender application that is using the default receiver.
I am passing a live MPEG-DASH stream and all is working.
I have one concern the time that is displayed in the seek bar is incorrect it looks like a malformation of an epoch timestamp.
example
416797:35:52
is there anything I can do to make this timestamp work?
I am currently getting an epoch timestamp back as currentTime from the remotePlayer
I have bound the RemotePlayerController like the following
this._remotePlayer = new cast.framework.RemotePlayer();
this._remoteController = new cast.framework.RemotePlayerController(this._remotePlayer);
This is because the duration for live is infinity. I had the same problem, I had to manually calculate progress to show it correctly, although you can't use it to seek to a position for live contents.
If you bind with RemotePlayerController it should handle this for you, this would basically disable seek bar and show you default -- -- start and end time.
At our office we check in by opening a webpage and clicking on a check-in button.The following function is called while clicking the button:
function checkInOutSubmit(thisController, thisAction, checkName){
var visitortime = new Date();
var visitortimezone = "GMT " + -visitortime.getTimezoneOffset() / 60;
var timeZone = jstz.determine_timezone();
var timeZoneName = timeZone.name();
var checkInCheckOut = checkName
jQuery.ajax({type:'POST',data:{checkInCheckOut:checkInCheckOut,currentController: thisController,currentAction: thisAction,timez:timeZoneName}, url:'/pms/attendanceForgot/checkInCheckOut',success:function(data,textStatus){jQuery('#successdiv').html(data);successCheckInOut();},error:function(XMLHttpRequest,textStatus,errorThrown){}});
}
But I want to put a old time when clicking on the button and not the current time.(If I reach click the button at 11:00am, I want to post 10:00am as my checkin time).
How can this be done?
There is not enough information here to answer your question.
All this code is doing is finding the current time zone, not the current time. It passes that to the server via an ajax request, which makes me think the time is generated server side. It's possible you could alter the logged time on the server by changing the timezone to an offset that would make it look like you are clocking in at the right time, but it would have to be some seriously deficient code on the server for that to work.
In almost all likelihood, the server is storing the time of the request in universal time as the clock in time and when you leave it's storing the time you leave in universal time as well. (think a point in time that isn't dependent on timezones) If your goal is get more hours, you'll just have to work later when you come in late. If you want it to look like you came in "on time", then changing the timezone might help until they notice that you've been there from 10am to 6pm but are only logging 7 hours.
I have an own PHP loginsystem. Users will be logged out after 5 min of inactivity.
Now I want to show a timer in the right top corner to display the countdown.
At the moment I am using javascript.
Like this (Pseudo, haven't my code here at the moment):
var myTime = <?php echo time(); ?>;
window.setInterval(myTime = myTime - 1; $("#timertext").text(myTime), 1000);
But I don't like this solution. I would like to use the current system time (php) and subtract the time, the user was active at last.
I found a solution to get the current system time via Ajax. But is this a good idea?
What do you think I could do to realize this counter? Is there a smart solution? Maybe a completely other way?
I want to display 3 clocks from 3 different time zones using JavaScript.
I browsed around the web searching for a simple solution but all I found was long scripts and .js extensions, all those to complete a simple task.
Is there an easy way to do this? do I really have to add an additional JS file to complete this task?
Thanks in advance to the helpers!
Is there an easy way to do this?
Yes.
do I really have to add an additional JS file to complete this task?
No. However, time handling in JS is difficult, since it has no really cross-browser-safe date/timestring parsing and formatting methods. It can be helpful to use a library for that, however that won't be necessary for your clock.
// all three clocks represent current time
var clock1 = new Date(); // current moment
var clock2 = new Date();
var clock3 = new Date();
// for outputting, adjust them
// leave clock1 in UTC
clock2.setHours(clock2.getHours() + 3); // UTC+3
clock3.setHours(clock3.getHours() - 5); // UTC-5
// now for display, use these values:
clock1.getUTCHours();
clock1.getUTCMinutes();
clock1.getUTCSeconds();
clock2.getUTCHours();
clock2.getUTCMinutes();
clock2.getUTCSeconds();
clock3.getUTCHours();
clock3.getUTCMinutes();
clock3.getUTCSeconds();
I have a simple JavaScript chronograph that displays on a form field called "d2", it is used to check how long someone takes on doing a specific task:
var milisec=0
var seconds=0
var complemento1=""
document.form1.d2.value='00:00:00'
function display(){
if (milisec>=9){
milisec=0
seconds+=1
}
else{
milisec+=1
}
complemento1=complemento2=complemento3="";
if ((seconds%60)<10) complemento1="0";
if ((Math.floor(seconds/60)%60)<10) complemento2="0";
if ((Math.floor(seconds/3600))<10) complemento3="0";
document.form1.d2.value=complemento3+Math.floor(seconds/3600)+":"+complemento2+(Math.floor(seconds/60)%60)+":"+complemento1+(seconds%60)
setTimeout("display()",100)
}
The problem is that when the person opens a new tab / uses another program the timer stops, and then resumes when the window is focused again (Using Chrome). It has the weirdest behavior, because sometimes it works, sometimes it doesn't.
I saw many posts that needed a script to stop when not on focus, I want the exact opposite and searched for over an hour with no luck. Your help is greatly appreciated!
JavaScript timeouts are not guaranteed be executed at a specific time. For example if the thread is busy with something else at the time when the timer finishes, it will first finish what it is doing and then execute your timer.
Also your function does not take into account the time spend inside the display function, so a little delay will be added for each millisecond.
The correct way to implement a timer is using the system time.
So something like:
//Call at the beggining to save the start time
var start_time = new Date()
// Compute seconds (does not matter when/how often you call it.)
var milliseconds_since_start = new Date().valueOf() - start_time
The Date object can also format this period as a clock for you:
var m = new Date(milliseconds_since_start)
m.getMinutes()+":"+m.getSeconds()