How To Print/Get Today Date and Time In JavaScript, C/C++, Python, C#, Java, PHP, PowerShell, Excel (VBScript) ? – POFTUT

How To Print/Get Today Date and Time In JavaScript, C/C++, Python, C#, Java, PHP, PowerShell, Excel (VBScript) ?

While developing applications date and time operations are very important. A lot of different data and record is bind to a date or time. We can also use the only date which specifies the year, month and day or time which specifies the hour, minute, second. All popular programming languages provides date and time functions to get the current date and time. In this tutorial, we will learn today date and time in different programming and scripting languages.

Today Date and Time Use Cases

Today date and time can be used in different situations. We can use today or the current date and time like the following use cases.

  • While publishing posts in web sites today date and time used to time stamp the date the post is created and published.
  • In order to store the actions and their time to analyze later like login, shopping, shipment.
  • In order to sort according to date like photos, posts, etc we have to set their creation date and time.

Today Date and Time In JavaScript

JavaScript programming language provides today date and time with the new Date() function which will create a new date and time object which will store current date and time. We will use attributes like getFullYear() , getMonth() , getDate() , getHours() , getMinutes() , getSeconds() function like below.

Today Date and Time In JavaScript

Today Date and Time In JavaScript

Today Date and Time In C/C++

C and C++ programming languages provides time.h headers with the time struct and localtime function. We can use these which will provide current or today date and time as tm type. Then tm_year , tm_mon , tm_today , tm_hour , tm_min, tm_sec struct elements can be used to get different data.

LEARN MORE  What Is Nettime and How To Use Nettime?

Today Date and Time In C/C++

Today Date and Time In C/C++

Today Date and Time In Python

Python programming language provides date and time functions in the datetime module. We can use date object today() function in order to get current or today date and time like below. We will use strftime() function with formatting parameters which are like below.

  • %d is Day
  • %m is Month
  • %Y is Year
  • %H is Hour
  • %M is Minute
  • %S is Second

Today Date and Time In Python

Today Date and Time In Python

Today Date and Time In C#

C# programming language provides DateTime library where Now attributes ToString() function can be used to get current today date and time and format properly into a string.

Today Date and Time In Java

Java provides the java.util library which containsDate() function which will provide the current day and time. We will also use Date type which can hold all date attributes like an hour, day, etc. We will also use some format in order to print the current date and time in string format.

LEARN MORE  What Is Linux Epoch Time and How To Convert To Human Readable Format?

Today Date and Time In PHP

PHP provides date() function which will provide today date and time. We can also format this information with some formatters like below.

  • Y is Year
  • m is  Month
  • d is Day
  • h is Hour
  • i is Minute
  • sa is Second

Today Date and Time In PHP

Today Date and Time In PHP

Today Date and Time In PowerShell

PowerShell provides Get-Date command in order to print the current date and time. We have to use -UFormat option in order to print Day/Month/Year Hour:Minute:Secondformat like below.

  • %Y is Year
  • %m is Month
  • %d is Day
  • %H is Hour
  • %M is  Minute
  • %S is Second

Today Date and Time In PowerShell

Today Date and Time In PowerShell

Today Date and Time In Excel (VBScript)

Excel office application supports Macros written in VBScript. We can get the current or today date and time with the NOW() function. We also need to use = to make NOW() function calculate.

Leave a Reply

Your email address will not be published. Required fields are marked *

Enjoy this blog? Please spread the word :)