Skip to main content

How to display date and time in Blogger withJAVASCRIPTt?

How to display date, time, and history in Blogger with Javascript with code Examples?

You can use the date object to work with time and date with JavaScript to Blogger.com post.

The date object has some methods that allow you to get and set the date and time and format the date and time in different ways.


How to display date and time in Blogger with  Javascript?


Here are some of the most common aq date in javascript methods:


new Date(): This method creates a new Date object with the current date and time.

getDate(): This method returns the day of the month.

getMonth(): This method returns the month of the year (0-11).

getFullYear(): This method returns the year.

getHours(): This method returns the hour of the day (0-23).

getMinutes(): This method returns the minutes of the hour (0-59).

getSeconds(): This method returns the seconds of the minute (0-59).

getMilliseconds(): This method returns the milliseconds of the second (0-999).

toDateString(): This method returns a string representation of the date in the format "YYYY-MM-DD".

toTimeString(): This method returns a string representation of the time in the format "HH:mm:ss".

toLocaleString(): This method returns a string representation of the date and time in the local time zone.

You can also use the Date object to create timestamps, which are numbers that represent the number of milliseconds since January 1, 1970. You can use timestamps to compare dates and times or to calculate the difference between two dates.


Here is an example of how to get the current date and time using the Date object:


const now = new Date();

console.log(now); // "2023-09-07T09:10:27.000Z"


This JAVASCRIPT code creates a new Date object called now and then prints the value of now to the console. The value of now is a string that represents the current date and time in the format "YYYY-MM-DDTHH:mm:ss.sssZ".


You can also use the Date object to format the date and time by different methods. For example, the following code formats the current date and time in the format "Month Day, Year":


const now = new Date();


const formattedDate = now.toLocaleString();


console.log(formattedDate); // "September 7, 2023"

This code creates a new Date object called now and then formats the value of now using the toLocaleString() method. The toLocaleString() method returns a string representation of the date and time in the local time zone.


Example:


Output:


display date and time in Javascript

Comments

Popular posts from this blog

Simple free calorie calculator BMR TDEE basal metabolic rate counter

Simple free calorie calculator BMR TDEE basal metabolic rate counter Have you ever wondered how many calories your body burns just by existing? That's where your Basal Metabolic Rate (BMR) comes in – the foundation for understanding your daily energy needs. But calculating BMR can feel like a scientific equation. Here's where BMR calculator tools come to the rescue! Simple free calorie calculator BMR TDEE basal metabolic rate counter What is a BMR Calculator Tool? An online BMR calculator is a user-friendly tool that estimates your Basal Metabolic Rate based on factors like age, weight, height, and gender. Simply input your information, click calculate, and voila! You'll have a personalized BMR estimate. Why is BMR Important? BMR is a crucial metric for anyone looking to manage their weight. It represents the minimum number of calories your body burns at rest to maintain vital functions. Knowing your BMR helps you: Set realistic weight loss/gain goals: By understanding you...

How to add a responsive code box in the blogger post clipboard copy button

How to add a stylish responsive code box in blogger post clipboard copy button In this post of Blogger coding tips , you learn how to create a code box for a blogger blogspot post clipboard that prevents visitors from copying code by using HTML, CSS, and JavaScript.  How to add a responsive code box in the blogger post clipboard copy button 1. Create HTML of blogger code box: Open the HTML view for your Blogger post and create the structure for your code box. Include a <pre> tag for the code and a button for copying. <div class="code-box">     <pre class="code">         <!-- Your code goes here -->     </pre>     <button class="copy-button" onclick="copyCode()">Copy Code</button> </div> 2. Code box Style with CSS: Add some styles to make your code box responsive and visually appealing. You can place the following styles in your post's CSS section or use inline styles within the HTM...

How to add Redirect 404 Not Found Page to the Home Page in Blogger

How to add automotive redirect 404 Not Found Page to the Home Page with  Blogger setting for broken links by javascript code Whenever someone goes on a web page that is either deleted or has no existence Blogger website usually displays its common 404 not found error message for broken links with simple Javascript code. “Sorry for the inconvenience, the page you are looking for has no existence”. The first impression counts more than anything. A person would never desire to display not-found error pages to his new visitors. Therefore, it is essential to redirect all 404 not found pages to the home page URL so users can easily get access to the content that is waiting for them.  So we learn how to use this simple JavaScript code which does the job pretty nicely.  How to add Redirect 404 Not Found Page to the Home Page in Blogger first, you must learn two main about redirect page messages 404 Pages: The 404 not found error message of Blogspot.com is a form of standard H...