Jump to content

setting time with batch file


Recommended Posts

I currently have a patch file that saves time i installed windows. right now using the %time% command i get hh.mm.ss.cc which is way more than i want. I would like the time to be save as just the hour and minutes as well if it is AM or PM. Can someone tell me what command i can add to my batch to perform this?

thanks

Link to comment
Share on other sites


There are many different ideas for doing this, however, the answers can vary a great deal because of the way different localities display their time data and different operating system functions.

A basic way based upon your current output (unknown as to whether it is in 12 or 24 hour format) is:

%TIME:~0,2%:%TIME:~3,2%

We would need more information in order to take this much further without over complicating matters.

Link to comment
Share on other sites

thanks for the help Yzöwl. Your code gives me part of what i want. I would rather the time be 12hr clock with am or pm instead of the military time your code shows. The system time on my computer is 12hr clock with am and pm

Edited by cumminbk
Link to comment
Share on other sites

I tried the batch file and nothing happens. The batch file just opens and sits there blank.

Also i am wondering if there is a simpler method other than that batch file. Is there a command that assumes I am using a clock that is 12hr and doesnt take into effect all different time zones and performing checks for 12 hr or 24 hour clocks and so on.

I liked what you posted first except i want 12hr clock and am or pm added to the time.

can you produce a line of code about the same length as this?

%TIME:~0,2%:%TIME:~3,2%

This time is just basically a time stamp. It does not have to update itself at intervals. just grab the current system time and save it to my file oobeinfo.ini

Edited by cumminbk
Link to comment
Share on other sites

The batch file should work as you requested. It uses WMIC and grabs the local time from your machine and puts it into the format you required.

Because it uses WMIC you need to be running at least XP as an administrator. If WMIC has never ran before on your system it will take a short time to set itself up before first use.

Link to comment
Share on other sites

I do not know if this is what you want. This cmd script does

1:\ Makes a VBS script that uses the time function

2:\ Creates a temp SetTime.cmd that passes the VBS Time to the original cmd.

Save As Time.cmd

@Echo Off
CLS
Color F3
Mode 55,5
Title Time
Set VBS=%SystemDrive%\Time.vbs
Set Cmd=%SystemDrive%\SetTime.cmd
> %VBS% Echo Dim TS
>> %VBS% Echo Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")
>> %VBS% Echo Set Ts = Fso.CreateTextFile("%Cmd%")
>> %VBS% Echo Ts.writeline "Set TM=" ^& Time '/-^> Varible For Time
>> %VBS% Echo Ts.Close
%VBS%
call %Cmd%
Del %VBS%
Del %Cmd%
Echo.
Echo -^> %TM%
pause

Link to comment
Share on other sites

Another Batch/VBS hybrid, see how this does you!

@Echo off&Setlocal&Set "VBS_=%TEMP%\_$.vbs"
>"%VBS_%" Findstr "'VBS$" "%~f0"
For /f "Delims=" %%? In ('CScript //NoLogo "%VBS_%"') Do Set T_=%%?
Del %VBS_%&Echo/%T_%&Pause&GoTo :Eof
tm = time() 'VBS
hr = hour(tm) 'VBS
mn = right("0" & minute(tm),2) 'VBS
Select case true 'VBS
case hr < 12 'VBS
ampm = "AM" 'VBS
case hr = 12 'VBS
ampm = "PM" 'VBS
case else 'VBS
ampm = "PM" 'VBS
hr = hr - 12 'VBS
end Select 'VBS
WScript.Echo hr & ":" & mn & " " & ampm 'VBS
'VBS

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...