Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

angularjs How to get time difference from ZoneDateTime in javascript

function getTimeDiff(data, date = new Date()) {
  let utc = new Date(Date.UTC(
      data.year, 
      data.monthValue - 1,
      data.dayOfMonth,
      data.hour,
      data.minute,
      data.second
  ) - data.offset.totalSeconds*1e3);
  return date - utc;
}

function msToTime(ms) {
  let days = ms / 8.64e7 | 0;
  let hrs = (ms%8.64e7) / 3.6e6 | 0;
  let mins = (ms%3.6e6) / 6e4 | 0;
  let secs = (ms%6e4) / 1e3 | 0;
  let z = n => (n<10? '0':'') + n;
  return `${days? days + ' day' + (days == 1? ' ' : 's ') : ''}${z(hrs)}:` +
         `${z(mins)}:${z(secs)}`;
}

let callStartTime = {
  chronology: {id: 'ISO', calendarType: 'iso8601'},
  dayOfMonth: 8,
  dayOfWeek: "TUESDAY",
  dayOfYear: 39,
  hour: 16,
  minute: 15,
  month: "FEBRUARY",
  monthValue: 2,
  nano: 240000000,
  offset: {totalSeconds: 19800, id: '+05:30', rules: {}},
  second: 29,
Comment

PREVIOUS NEXT
Code Example
Javascript :: angularjs New Entry Not reflacting in table after inserting New record in CRUD angular app 
Javascript :: Automatic display keyed value in a dynamic table row using javascript, angular js and html 
Javascript :: Popover AngularJs quickly disappearing 
Javascript :: Angular after click add active class and remove from siblings 
Javascript :: angular chart js graph legend colors 
Javascript :: How to get one items from my Firebase realtime Database with Angular Ionic 
Javascript :: convert base64 formatted data to image using AngularJs 
Javascript :: React Native, <TextInput onChange{(text) = setState(text)} is returning an object instead of a string. Eventhough the default value is a String. Why 
Javascript :: React Native Swift Escaping closure 
Javascript :: How to make this code cleaner? react native 
Javascript :: Save multiple radios checked on LocalStorage 
Javascript :: gradient of a function 
Javascript :: in node.js with express how to remove the query string 
Javascript :: request submit form 
Javascript :: filter a object array tree javascript 
Javascript :: react native push notifications cancel delivered notification 
Javascript :: Odoo Javascript Modules 
Javascript :: function x(a) vs function x(...a) the difference 
Javascript :: Class Which Can Create An Instance Of The Same Type 
Javascript :: Vue Js The specified value cannot be parsed, or is out of range 
Javascript :: underscore js 
Javascript :: call axios post with an interval 
Javascript :: como hacer un contador de tiempo en javascript 
Javascript :: Using an object of functions as a parameter into a function 
Javascript :: console.log(number++); console.log(++number); console.log(number); 
Javascript :: PostManDocs 
Javascript :: wait untill 2 
Javascript :: Different Pages For Different Routes In Backbone 
Javascript :: Wrong Model Name For Backbone: Code Still Runs 
Javascript :: empty an array in javascript 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =