Monday, July 4, 2022
HomeSoftware DevelopmentSecond.js second.length().weeks() Technique - GeeksforGeeks

Second.js second.length().weeks() Technique – GeeksforGeeks


View Dialogue

Enhance Article

Save Article

Like Article

The second().length().weeks() technique is used to get the weeks of the length. This variety of weeks is calculated as a subset of the times, subsequently having a worth between 0 and 4. The size of days for calculating every week is 7 days.

This technique is totally different from the asWeeks() technique which returns the size of the given length in weeks.

Syntax:

second().length().weeks();

Parameters: This technique doesn’t settle for any parameters.

Return Worth: This technique returns the weeks (0-4) of the length.

Observe: This is not going to work within the regular Node.js program as a result of it requires an exterior second.js library to be put in globally or within the challenge listing.

Second.js will be put in utilizing the next command:

Set up of second module:

npm set up second

The beneath examples will exhibit the Second.js second.length().weeks() Technique.

Instance 1: 

Javascript

const second = require('second');

  

let durationOne = second.length(3, 'weeks');

let durationTwo = second.length(6, 'weeks');

  

console.log(

  "durationOne Weeks is:", durationOne.weeks()

)

  

console.log(

  "durationTwo Weeks is:", durationTwo.weeks()

)

Output:

durationOne Weeks is: 3
durationTwo Weeks is: 1

Instance 2: This instance will assist to know the distinction of this technique with asWeeks() for a greater understanding.

Javascript

const second = require('second');

  

let durationA = second.length(30, 'days');

let durationB = second.length(38, 'days');

  

console.log(

  "Size of durationA in weeks is:",

  durationA.asWeeks()

)

  

console.log(

  "durationA Weeks is:", durationA.weeks()

)

  

console.log(

  "Size of durationB in weeks is:",

  durationB.asWeeks()

)

console.log(

  "durationB Weeks is:", durationB.weeks()

)

Output:

Size of durationA in weeks is: 4.285714285714286
durationA Weeks is: 4
Size of durationB in weeks is: 5.428571428571429
durationB Weeks is: 1

Reference: https://momentjs.com/docs/#/durations/weeks/

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments