Published on January 26, 2024By DeveloperBreeze

// Function to format a date
function formatDate(date) {
    // Define formatting options
    const options = { year: 'numeric', month: 'short', day: 'numeric' };
    
    // Use toLocaleDateString to format the date
    return new Date(date).toLocaleDateString('en-US', options);
}

// Get the current date
const currentDate = new Date();

// Format the current date using the formatDate function
const formattedDate = formatDate(currentDate);

// Log the formatted date to the console
console.log('Formatted Date:', formattedDate);

Comments

Please log in to leave a comment.

Continue Reading:

Date Formatting for Specific Date ('Y-m-d')

Published on January 26, 2024

php

Generate MySQL-Formatted Dates

Published on January 26, 2024

php