Questions tagged [dayjs]

Day.js is an immutable date library for JavaScript

Day.js is a minimalist JavaScript library that parses, validates, manipulates, and displays dates and times for modern browsers with a largely Moment.js-compatible API.

https://github.com/iamkun/dayjs

Stack Snippet Starter Pack

(from day.js.org)

HTML

<script src="https://unpkg.com/dayjs@1.8.21/dayjs.min.js"></script>

JavaScript

console.log(dayjs().format())

Useful links

281 questions
0
votes
1 answer

How can I render date in the browser using Day.js?

I want to render a date into the element using Dayjs. How do I go about doing this? I have dayjs imported from a CDN in a script tag at the bottom of the html document.
0
votes
1 answer

Display dayjs time from when post was created

So I have an express app where you can make posts and such. I want to display how long ago the post was made ie. 5 minutes ago. I have been looking at day.js docs and they say to use: dayjs(date).fromNow(); The problem with this is that it is…
user
  • 1,022
  • 2
  • 8
  • 30
0
votes
1 answer

How to get remaining days from dayjs when getting months

So I'm having trouble finding a solution to this online, and if there's one thing I hate; it's working with dates. I need to be able to calculate a person's age in months and days. So if they were born July 3rd, 2020 I need something like 2 months,…
blaze-rowland
  • 117
  • 1
  • 4
  • 11
0
votes
1 answer

From Object to dayJs

Is it possible to create a dayjs with and Object?. For example, in moment we have. let newDate = moment({years:2000,months:1,days:1}) which will create a moment date.
Carlos1232
  • 815
  • 6
  • 15
0
votes
1 answer

Using dayjs with Sapper

I have been using moment.js in a page in my Sapper app. When I build the project, I noticed that moment.js takes up quite some space, so I tried to switch over to dayjs instead. However, whenever I try to open the page in which I am using day.js,…
psc212
  • 73
  • 2
0
votes
1 answer

how can i improve method that returns created time diff like ( 30s, 5m, 3h, 1y ago ) in >= ES6

here is my code what i am trying to achieve is the time similar to youtube/fb/instagram, show the posting time diff like: 30s ago 5m ago 15h ago 6d ago 1w ago 5y ago the code is working fine, but is to verbose, and i am wondering if some js "guru"…
Ion Utale
  • 551
  • 1
  • 9
  • 22
0
votes
0 answers

Problem when decrease seconds at Day.js for countdown timer (trying to migrate from moment.js)

I have a working code from someone about countdown timer using Moment.JS --> [his code: https://codepen.io/javanigus/pen/KrMRvd ] . Im trying to replicate it using Day.JS, you could say i want to migrate it from moment.js to day.js . I success to…
0
votes
1 answer

Why does summing up a variable from an array give me NaN? (Javascript)

I have this array containing appointments: let appointments = [ {"appointmentId": 001239, "subject": "Something", "Client": "Bob", "StartTime": "2020-04-16T11:00:00.000Z", "EndTime": "2020-04-16T11:30:00.000Z", "km": 90}, {"appointmentId": 001240,…
Y_Lakdime
  • 825
  • 2
  • 15
  • 33
0
votes
1 answer

Mongoose Query: Compare one value with another transformed value of the same document

I need to query dates in the paidUntilDate property that are x days later than today, where x is in the property notificationDaysBefore of the same document. I'm using the dayjs library to query dates. I found that I could compare values in the same…
edrichhans
  • 113
  • 1
  • 2
  • 11
0
votes
1 answer

dayjs - how to create an ISO datetime string in a different timezone?

I am building an browser-based application where the user sets the timezone of their application, e.g. "America/New_York". I have a part of the application that allows users to set reminders and I want the user to specify that they want, for…
JoeTidee
  • 24,754
  • 25
  • 104
  • 149
0
votes
1 answer

Is there any "ember-moment-shim" alternative for dayJS?

ember-moment-shim is an ember addon that generates the locales conditionally based on Moment.js and Moment-Timezone. Any tools or processes to accomplish the same with just DayJs instead. Ref:…
Sarath Damaraju
  • 309
  • 2
  • 13
0
votes
1 answer

Dayjs custom locale throws Formatting exceptions

I want to create a custom locale and use it with DayJs. and the procedure is mentioned here in docs But, when I follow the procedure and create my own locale, I am unable to format the date after. Here is the JSFiddle to inspect the…
Sarath Damaraju
  • 309
  • 2
  • 13
-1
votes
1 answer

How to extract UTC offset from given date

I use Dayjs library for date parsing/manipulation in nodejs. Consider a date = "2023-07-21T12:00:00+05:00". When I try to get utcOffset by using dayjs(date).utcOffset() it returns "60" in minutes, although offset in minutes of given date is "300". I…
-1
votes
1 answer

moving moment to dayjs in react

I was using moment in my react application earlier I changed to dayjs before code: moment.duration(moment().diff(moment(timeString))); after code : dayjs.duration(dayjs().diff(dayjs(timeString))); I am getting this error: dayjs.duration is not a…
-1
votes
1 answer

Set hour to timeblock element using dayjs().hour()

I am trying to set a Day.js hour object to an element. I am using dayjs().hour(9), but it is returning too much information. I just want the hour block but when I console.log it comes back with day of the week date time with mins and seconds. In…
1 2 3
18
19