javascript
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.