Help with Date and Time

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
RightBehindu
Posts: 26
Joined: 23 Dec 2013 07:07

Help with Date and Time

#1 Post by RightBehindu » 18 Aug 2014 22:17

Hello everyone!

I am in a bit of a pickle. I need some help grabbing info of date and time. I know how to get date and time on my own computer, although I would specifically like to get world time, or for a specific place, like American or Australian time. Don't bother asking for why, but it is imperative. The only other way I can think is to grab the IP address of the users computer, and find the location of this computer, and then just edit that time to match another place, but the former would be much more practical.

If you have any idea on how to do this, latter or former ways, I would be very grateful.

Thanks in advance.

~ Matt.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Help with Date and Time

#2 Post by foxidrive » 19 Aug 2014 06:36

RightBehindu wrote:Don't bother asking for why, but it is imperative.


if you paid a programmer to help you then you would have to tell them everything about the task.
How come you think it is different when you ask for help for free?

pieh-ejdsch
Posts: 257
Joined: 04 Mar 2014 11:14
Location: germany

Re: Help with Date and Time

#3 Post by pieh-ejdsch » 19 Aug 2014 06:54

Hi,

with wget you can download this html Site:

Code: Select all

http://24timezones.com/de_weltzeit/berlin_aktuelle_zeit.php


local timestring is to search in this downloaded File eg:

Code: Select all

<span id="currentTime">14:52:52, Dienstag 19, August 2014</span>


when website time and localtime is equal then read out this string "UTC/GMT +1 Stunde"

Phil

RightBehindu
Posts: 26
Joined: 23 Dec 2013 07:07

Re: Help with Date and Time

#4 Post by RightBehindu » 19 Aug 2014 07:45

Thanks a lot Phil. That will be very helpful.

And why I did not state why, is because I didn't need to. I told what I wanted to do with no details left out, the reason why I want it doesn't matter. If it effected the process of getting it, then I would have given it to you, but Phil did it fine.

Thanks again.

P.S Foxidrive, maybe just try help to the best you can if you are going to respond at all, because criticizing the question is not helping anyone, with the exception that the question is impossible to understand.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Help with Date and Time

#5 Post by Squashman » 19 Aug 2014 08:03

Some times the WHY clarifies how the script should be coded.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Help with Date and Time

#6 Post by foxidrive » 19 Aug 2014 09:46

RightBehindu wrote:I told what I wanted to do with no details left out, the reason why I want it doesn't matter.


This is how I look at it. Someone asks a question to get free help and the people that reply again and again are not robots and actually enjoy knowing how they are helping and seeing real details about the task.

P.S Foxidrive, maybe just try help to the best you can if you are going to respond at all, because criticizing the question is not helping anyone, with the exception that the question is impossible to understand.


When you have helped people with batch code for 20 years, have never taken any money, never met any of the people,
and you spend hours every day doing it, you might begin to understand that you get sick of seeing questions that
ask for free help but don't give you any real information - and Squashman knows, the best code is written for the actual task.


So many posters these days fail to even reply when they get a solution. Very many of them don't bother to say thank you.
Too many of them give you too few or bogus details.

So I ignore many posts these days which have no details, and comment on some posts like yours where you say

Don't bother asking for why, but it is imperative.

RightBehindu
Posts: 26
Joined: 23 Dec 2013 07:07

Re: Help with Date and Time

#7 Post by RightBehindu » 19 Aug 2014 17:34

I see.

Thank you for your hard work then. If you must know, it is for a project I am working on, a game in particular, where a specific feature locks at a certain time. Although, this time would vary dependent on the users computer clock. This is why I needed a constant time to work from, therefore all users would have the same timing. The reason they need the same timing is because it is online and they can interact with each other.

Thanks again to all of you :)

~ Matt.

RightBehindu
Posts: 26
Joined: 23 Dec 2013 07:07

Re: Help with Date and Time

#8 Post by RightBehindu » 20 Aug 2014 00:51

Going on the information Phil has given me, I am not sure on how to get the specific information.

How would I be able, from the clump of php code in this php, grab the time within that and either set it to a variable, or send it to a file.

Thanks again.

~Matt

P.S the time that I would like, is the span showed in Phils response above.
<span id="currentTime">07:31:26, Wednesday 20, August 2014</span>

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Help with Date and Time

#9 Post by foxidrive » 20 Aug 2014 08:53

I get it in German I think - is that what you want?

<span id="currentTime">16:50:57, Mittwoch 20, August 2014</span>


Do you just want the time itself?

RightBehindu
Posts: 26
Joined: 23 Dec 2013 07:07

Re: Help with Date and Time

#10 Post by RightBehindu » 20 Aug 2014 17:35

Yes, I am just looking for them time. And if possible, maybe put the date in a variable too. I am not too knowledgeable on the use of the for command, so I am not really sure on how to do it.

Thanks

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Help with Date and Time

#11 Post by foxidrive » 20 Aug 2014 22:00

Try this batch file and launch it like so:

Code: Select all

file.bat http://24timezones.com/de_weltzeit/berlin_aktuelle_zeit.php



Code: Select all

@echo off
if "%~1"=="" (
echo %0 http://www.url.com
echo.
pause
goto :EOF
)


 >"%temp%\geturl.vbs" echo Set objArgs = WScript.Arguments
>>"%temp%\geturl.vbs" echo url = objArgs(0)
>>"%temp%\geturl.vbs" echo pix = objArgs(1)
>>"%temp%\geturl.vbs" echo With CreateObject("MSXML2.XMLHTTP")
>>"%temp%\geturl.vbs" echo .open "GET", url, False
>>"%temp%\geturl.vbs" echo .send
>>"%temp%\geturl.vbs" echo a = .ResponseBody
>>"%temp%\geturl.vbs" echo End With
>>"%temp%\geturl.vbs" echo With CreateObject("ADODB.Stream")
>>"%temp%\geturl.vbs" echo .Type = 1 'adTypeBinary
>>"%temp%\geturl.vbs" echo .Mode = 3 'adModeReadWrite
>>"%temp%\geturl.vbs" echo .Open
>>"%temp%\geturl.vbs" echo .Write a
>>"%temp%\geturl.vbs" echo .SaveToFile pix, 2 'adSaveCreateOverwrite
>>"%temp%\geturl.vbs" echo .Close
>>"%temp%\geturl.vbs" echo End With

set "t="
set "d="

cscript /nologo "%temp%\geturl.vbs" %1 url.htm 2>nul
if not exist url.htm (
echo site is down or access is denied
) else (
for %%a in (url.htm) do if %%~za GTR 0 echo site is up

for /f "tokens=3,4,5 delims=<>," %%a in (' find "<span" ^< "url.htm" ') do (
  if not defined t set t=%%a
  if not defined d set d=%%b %%c
)
del url.htm
)
echo %t%, %d%
del "%temp%\geturl.vbs"
pause

RightBehindu
Posts: 26
Joined: 23 Dec 2013 07:07

Re: Help with Date and Time

#12 Post by RightBehindu » 20 Aug 2014 23:59

I understand none of that. Haha. Although I will do my best. Is there a way you could do a little explanation for me? I know lots, but once your get into the for commands and Vbs and alike, I get a little lost.

Thanks

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Help with Date and Time

#13 Post by foxidrive » 21 Aug 2014 04:16

Ask a question about a part that you'd like some explanation about.

The VBS script just downloads a page from the URL.

The for /f splits the line up (which is filtered by the find command) into sections that are separated by the delims.

When delims are < and > and , then they are removed and the remaining parts of the line are separated into tokens

The first part is token 1, the second is token 2 etc

so in this case a line like this:

abc<def>123,456

would become abc=token1 and def=token2 and 123=token3 and 456=token4

The tokens= allows you to pick which tokens you need, and when used then * becomes the last token for the rest of the line.

When you use %%a as the loop variable then the tokens you pick are assigned to %%a and %%b and %%c and %%d and %%e etc in the order you have selected.

Post Reply