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
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.
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.
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.
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.
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())"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With