Skip to content

Commit

Permalink
Enhance date function
Browse files Browse the repository at this point in the history
  • Loading branch information
kekefreedog committed Feb 18, 2024
1 parent 684b0f1 commit 3f86b0b
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Front/Library/Utility/DateTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default class DateTime {

// Return result
return `${year}/${month}/${day}`;

}

/**
Expand Down Expand Up @@ -174,16 +174,21 @@ export default class DateTime {
}

/**
* Get Today Date
*
* As YYYY-MM-DD
*
* @param separator By default "-"
* @returns {string}
*/
public static getTodayDate = ():string => {
public static getTodayDate = (separator:string = "-"):string => {

const today = new Date();
const year = today.getFullYear(); // Gets the full year (e.g., 2024)
const month = (today.getMonth() + 1).toString().padStart(2, '0'); // Month is 0-indexed, add 1 to get 1-12
const day = today.getDate().toString().padStart(2, '0'); // Day of the month

return `${year}-${month}-${day}`;
return `${year}${separator}${month}${separator}${day}`;

}

Expand Down

0 comments on commit 3f86b0b

Please sign in to comment.