Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

date-fns format

//Parse date string to date object. Use parse
const dateString = '10-13-20';
const date = parse(dateString, 'MM-dd-yy', new Date()) // not MM-DD-YY
//Format date object to result string. Use format
const result = format(date, "yyyy-MM-dd'T'HH:mm:ss.SSSxxx")
console.log(result)
//Result will be like (the same with moment's result in my timezone):
// 2020-10-13T00:00:00.000+09:00
Comment

date-fns

import { format, formatDistance, formatRelative, subDays } from 'date-fns'

format(new Date(), "'Today is a' eeee")
//=> "Today is a Tuesday"

formatDistance(subDays(new Date(), 3), new Date(), { addSuffix: true })
//=> "3 days ago"

formatRelative(subDays(new Date(), 3), new Date())
//=> "last Friday at 7:26 p.m."
Comment

date-fns format

import { format, formatDistance, formatRelative, subDays } from 'date-fns'

format(new Date(), "'Today is a' eeee")
//=> "Today is a Saturday"

formatDistance(subDays(new Date(), 3), new Date(), { addSuffix: true })
//=> "3 days ago"

formatRelative(subDays(new Date(), 3), new Date())
//=> "last Friday at 7:26 p.m."
Comment

date-fns format

const date = "2021-12-20"
console.log(format(parseISO(date), "dd-MM-yyyy"));
// output: 20-12-2021
Comment

date-fns

format(new Date(), "'Today is a' eeee")
Comment

PREVIOUS NEXT
Code Example
Javascript :: max value in an array 
Javascript :: react responsive nav bar 
Javascript :: address validation in javascript 
Javascript :: Uncaught TypeError: $(...).datatables is not a function 
Javascript :: LRANGE in redis 
Javascript :: Use the parseInt Function 
Javascript :: what is my version of linux mint 
Javascript :: arcgis for javascript 
Javascript :: apply css to shadow dom 
Javascript :: check if jwt token is valid 
Javascript :: javascript cheat sheet 
Javascript :: js rename property 
Javascript :: axios 
Javascript :: take a screenshot javascript of canvas 
Javascript :: jquery scroll to bottom of div 
Javascript :: update property of object in array javascript 
Javascript :: Get Value of JSON As Array 
Javascript :: javascript promise with ajax 
Javascript :: js define constant by element id 
Javascript :: req is not defined 
Javascript :: how to stop angular server 
Javascript :: modal javascript 
Javascript :: node.js 
Javascript :: solidity payable 
Javascript :: buffer concat nodejs 
Javascript :: npm start browser 
Javascript :: how to set option value in fstdropdown using ajax 
Javascript :: ng2-tel-input phone number code 
Javascript :: search as text elastic search 
Javascript :: js await 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =