Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get date and time on the same line

I can use date /t and time /t to get the date and time, but it doesn't display it next to each other. I wanted to make it do that and display like this:

Current Date & Time -------------------  11/27/2013 10:43:05 AM 
like image 608
Aaron Avatar asked Nov 27 '13 15:11

Aaron


People also ask

How do I get the current date and time in CMD?

Display or set the system time. TIME /T Key new_time : The time as HH:MM TIME with no parameters will display the current time and prompt for a new value. Pressing ENTER will keep the same time. /T : Just display the time, formatted according to the current Regional settings.

How do I show date and time in PowerShell?

The Get-Date cmdlet gets a DateTime object that represents the current date or a date that you specify. Get-Date can format the date and time in several . NET and UNIX formats. You can use Get-Date to generate a date or time character string, and then send the string to other cmdlets or programs.

How do you loop in PowerShell?

The While statement in PowerShell is used to create a loop that runs a command or a set of commands if the condition evaluates to true. It checks the condition before executing the script block. As long as the condition is true, PowerShell will execute the script block until the condition results in false.

How do I use SubString in PowerShell?

The Substring method can be used on any string object in PowerShell. This can be a literal string or any variable of the type string. To use the method we will need to specify the starting point of the string that we want to extract. Optionally we can specify the length (number of characters), that we want to extract.


1 Answers

Try the following (PowerShell):

Get-Date -Format G  27.11.2013 17:10:23 

The format is defined with the system's regional settings, so for me this is what I get, but if you're regional date/time format is what you want, it should show up like you want.

(Get-Date).ToString() 

would probably also work.

UPDATE:

"Date and time is: $((Get-Date).ToString())" 
like image 170
Frode F. Avatar answered Sep 24 '22 09:09

Frode F.