0

i have a batch process in which i need to print IST time and GMT time in log. Can you please suggest how to achive this. I am using %date% and %time% as of now to print system date and my system is in IST.

Thanks in Advance.

Nishant
  • 63
  • 1
  • 2
  • 11
  • Which programming language you're using? – Jitendra Pancholi Mar 03 '15 at 13:25
  • i am talking about .bat file. – Nishant Mar 03 '15 at 13:28
  • on windows platform. – Nishant Mar 03 '15 at 13:29
  • `wmic os get LocalDateTime` command returns _local date and time_ in the [CIM_DATETIME](https://msdn.microsoft.com/en-us/library/aa387237(v=vs.85).aspx) format with current three-digit offset indicating the number of minutes that the originating time zone deviates from `UTC`. Not hard to count `UTC` (i.e. `GMT`) date and time values... – JosefZ Mar 03 '15 at 15:22
  • possible duplicate of [How do I set the timezone from command line ?](http://stackoverflow.com/q/16656229/2152082) – Stephan Mar 03 '15 at 15:25
  • If PowerShell is an option, see http://blogs.msdn.com/b/rslaten/archive/2014/08/04/converting-times-from-one-time-zone-to-another-time-zone-in-powershell.aspx – user4317867 Mar 04 '15 at 01:23

1 Answers1

0

Please give me the code you are using. That would help me better. But you may be able to use this code:

@echo off
cls
echo Universal Time Coordinated:
echo.
powershell "[DateTime]::UtcNow.ToString('MM/dd/yyyy HH:mm:ss')"
echo _______________________________________________________
echo.
tzutil /g
echo :
echo.
powershell "Get-Date -Format 'MM/dd/yyyy HH:mm:ss'"
pause>nul

and the more prefered:

@echo off
color f0
:time
cls
echo Universal Time Coordinated:
echo.
powershell "[DateTime]::UtcNow.ToString('MM/dd/yyyy HH:mm:ss')"
echo _______________________________________________________
echo.
tzutil /g
echo :
echo.
powershell "Get-Date -Format 'MM/dd/yyyy HH:mm:ss'"
timeout /t 1 /nobreak>nul
cls
goto time

Which refresh's the time every second.


You can use tzutil /g to display the current timezone. For more info or for help read the following:

Windows Time Zone Utility

Usage:
TZUTIL </? | /g | /s TimeZoneID[_dstoff] | /l>

Parameters:
    /? Displays usage information.

    /g Displays the current time zone ID.

    /s TimeZoneID[_dstoff]
       Sets the current time zone using the specified time zone ID.
       The _dstoff suffix disables Daylight Saving Time adjustments
       for the time zone (where applicable).

    /l Lists all valid time zone IDs and display names. The output will
       be: 
           <display name>
           <time zone ID>

Examples:
    TZUTIL /g
    TZUTIL /s "Pacific Standard Time"
    TZUTIL /s "Pacific Standard Time_dstoff"

Remarks:
    An exit code of 0 indicates the command completed successfully.

You can also use powershell get-date to find your current date and time. You can use powershell