Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

time date utils

import moment from "moment";
export const getLastPostDuration = (date) => {
  const now = moment(date);
  const expiration = moment();
  const diff = expiration.diff(now);
  const diffDuration = moment.duration(diff);
  if (diffDuration.hours() < 1 && diffDuration.days() < 1) {
    return moment(date).startOf("minutes").fromNow();
  }
  if (diffDuration.days() >= 6) {
    return moment(date).format("D MMM YY, h:mm a");
  }
  return moment(date).calendar().replace(" at ", ", ");
};
export const getTimeDuration = (duration) => {
  let seconds = Math.floor((duration % 1) * 60);
  let minutes = Math.floor(duration);
  let hours = 0;
  if (minutes > 60) {
    hours = minutes / 60;
    minutes = (hours % 1) * 60;
    hours = Math.floor(hours);
  }
  let newDuration = "";
  if (hours > 0) {
    newDuration += hours + " h ";
  }
  if (minutes > 0) {
    newDuration += minutes + " min ";
  }
  if (seconds > 0) {
    newDuration += seconds + " sec";
  }
  return newDuration;
};
export const mmss = (secs) => {
  const formatted = moment.utc(Math.round(secs) * 1000).format("mm:ss");
  return formatted;
};
export const covertMiliToDays = (milli) => {
  let minutes = Math.floor(milli / 60000);
  let hours = Math.round(minutes / 60);
  let days = Math.round(hours / 24);

  return (
    (days && { value: days, unit: "days" }) ||
    (hours && { value: hours, unit: "hours" }) || {
      value: minutes,
      unit: "minutes",
    }
  );
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript ping ip address 
Javascript :: convert todays date to json datetime 
Javascript :: nodejs createwriteStream file image broken 
Javascript :: get last day of month js 
Javascript :: currentContract.transferFrom is not a function 
Javascript :: Backbone Render And Initialize 
Javascript :: bind() method #1 
Javascript :: RTC measure react native undefined 
Javascript :: Last digit of a large number 
Javascript :: Joining two arrays with lookup 
Javascript :: changetypeprofiles 
Javascript :: check if function exists 
Javascript :: qiankun angular 
Javascript :: jquery check screen width 
Javascript :: append different object in object javascript 
Javascript :: generate qr codes js 
Javascript :: unreachable code detected javascript 
Javascript :: numberformat chakra 
Javascript :: convert array to conventional array js 
Javascript :: $() in javascript 
Javascript :: regex mobile 
Javascript :: javascript custom table 
Javascript :: node_modules is not generated in docker 
Javascript :: jquery code convert into javascript online 
Javascript :: page object 
Javascript :: how to get specific property name with numbers from object in javascript 
Javascript :: 3336tfsdfd 
Javascript :: javascript flow function 
Javascript :: p5.js sketch 
Javascript :: javascript code to run colab in background 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =