Utility Functions React

Round number with comma separator at thousands

export const roundedCommaSepartedNumber= (number:number)=>{
    const result = Math.round(number).toLocaleString();
    return result;
}

for example,

const roundedNumber = roundedCommaSepartedNumber(104400000.365) = 104,400,000 

Format Date String to Human Readable Date format

export const formatDate = (date:string)=>{
   const result =  new Date(date).toLocaleDateString('en-US', {
        year:'numeric',
        month:'long',
        day:'numeric'
      })
    return result;
}

for example,

const formatedDate = formatDate(2024-05-28T05:48:28.328Z) = May 28, 2024 

Format Date String to Human Readable Time format

export const formatTime = (time:string)=>{
    const result=  new Date(time).toLocaleTimeString('en-US', {
        hour:'2-digit',
        minute:'2-digit'
      })
    return result;
}

for example,

const formatedDate = formatTime(2024-05-28T05:48:28.328Z) = 11:48 AM