Page 7 of 8

Re: How get data/time independent from localization

Posted: 22 Oct 2015 14:03
by aGerman
@Squashman
Either of these commands does work. But if I'm not totally blind there isn't any time or date output.

Are these performance counter translated

At least these object names are not translated for me.

Re: How get data/time independent from localization

Posted: 22 Oct 2015 14:24
by Squashman
aGerman wrote:@Squashman
Either of these commands does work. But if I'm not totally blind there isn't any time or date output.

Are these performance counter translated

At least these object names are not translated for me.

Not from that specific LOGMAN option. I was just trying to find out if the GUID's are the same. Then we could use a different LOGMAN option using that GUID to get the date time output. Just wanted to know if the GUID's are the same for everyone regardless of language.

Re: How get data/time independent from localization

Posted: 22 Oct 2015 15:37
by npocmaka_
Squashman wrote:
aGerman wrote:@Squashman
Either of these commands does work. But if I'm not totally blind there isn't any time or date output.

Are these performance counter translated

At least these object names are not translated for me.

Not from that specific LOGMAN option. I was just trying to find out if the GUID's are the same. Then we could use a different LOGMAN option using that GUID to get the date time output. Just wanted to know if the GUID's are the same for everyone regardless of language.



Code: Select all

>logman query providers {36C23E18-0E66-11D9-BBEB-505054503030}

Provider                                 GUID
-------------------------------------------------------------------------------
Microsoft-Windows-Diagnostics-Networking {36C23E18-0E66-11D9-BBEB-505054503030}


same here though very few thing are localized on bulgarian versions of windows.And how this can be used with typeperf :?:




I think network abbreviations are not translated even on japanese Windowses based on what searched on google.
UDPv4 prints the less information and on my machine delay is around 1 sec (with about half a second if put |Findstr in the for definition I think with IF condition it is faster)

The problem is that on windows XP there's only one UDP protocol called UDP (no UDP version 6) so I've tried to made the fastest possible check - through environment variable:

Code: Select all

@echo off
setlocal

::check if windows is XP
if defined USERDOMAIN_roamingprofile (set "v=v4") else (set "v=")

set "mon="
for /f "skip=2 delims=," %%# in ('typeperf "\UDP%v%\*" -si 0 -sc 1') do (
   if not defined mon (
      for /f "tokens=1-7 delims=.:/ " %%a in (%%#) do (
        set mon=%%a
        set date=%%b
        set year=%%c
        set hour=%%d
        set minute=%%e
        set sec=%%f
        set ms=%%g
      )
   )
)

echo %year%%mon%%date%
echo %hour%%minute%%sec%%ms%
endlocal

Re: How get data/time independent from localization

Posted: 23 Oct 2015 10:37
by Squashman
I searched through this thread and I don't see anyone asking about the NET TIME command. I would assume this is regional dependent as well.

Code: Select all

H:\>NET TIME \\%ComputerName%
Current time at \\Squashputer is 10/23/2015 11:37:26 AM

Re: How get data/time independent from localization

Posted: 23 Oct 2015 14:32
by mcnd
I think I have not seen this used in this topic.

Code: Select all

set "year="
for /f "tokens=1-6 delims=/: " %%a in ('robocopy "|" . /njh') do if not defined year (
    set "year=%%a" & set "month=%%b" & set "day=%%c"
    set "hour=%%d" & set "min=%%e"   & set "sec=%%f"
)

echo %year%/%month%/%day% %hour%:%min%:%sec%


The basic idea is to force an error in the robocopy command and parse the date and time of the error in the output.

Re: How get data/time independent from localization

Posted: 23 Oct 2015 14:37
by Squashman
mcnd wrote:
The basic idea is to force an error in the robocopy command and parse the date and time of the error in the output.

Page3 viewtopic.php?p=29762#p29762
Robocopy is not native to XP. You also can just use ROBOCOPY. You don't need to force any error to it.

Re: How get data/time independent from localization

Posted: 23 Oct 2015 15:06
by mcnd
Squashman wrote:Page3 viewtopic.php?p=29762#p29762


Page 4 shows that the output is language dependant

Also, for me, with a limited user without rights over the root of the drive, the indicated command fails.

Squashman wrote:Robocopy is not native to XP


Yes, I know. Included here just for completion as I saw robocopy used in other posts.

Squashman wrote: You also can just use ROBOCOPY. You don't need to force any error to it.


Forcing the error we get date/time in yyyy/mm/dd hh:nn:ss format without even hitting the file system.

Re: How get data/time independent from localization

Posted: 23 Oct 2015 16:09
by Squashman

Code: Select all

C:\>robocopy

-------------------------------------------------------------------------------
   ROBOCOPY     ::     Robust File Copy for Windows

-------------------------------------------------------------------------------

  Started : Fri Oct 23 17:08:43 2015

       Simple Usage :: ROBOCOPY source destination /MIR

             source :: Source Directory (drive:\path or \\server\share\path).
        destination :: Destination Dir  (drive:\path or \\server\share\path).
               /MIR :: Mirror a complete directory tree.

    For more usage information run ROBOCOPY /?


****  /MIR can DELETE files as well as copy them !

C:\>robocopy |find "Started :"
  Started : Fri Oct 23 17:08:55 2015

C:\>

Re: How get data/time independent from localization

Posted: 23 Oct 2015 16:39
by npocmaka_
mcnd wrote:I think I have not seen this used in this topic.

Code: Select all

set "year="
for /f "tokens=1-6 delims=/: " %%a in ('robocopy "|" . /njh') do if not defined year (
    set "year=%%a" & set "month=%%b" & set "day=%%c"
    set "hour=%%d" & set "min=%%e"   & set "sec=%%f"
)

echo %year%/%month%/%day% %hour%:%min%:%sec%


The basic idea is to force an error in the robocopy command and parse the date and time of the error in the output.



This is clever and fast , though the info header with day of the week is missing (one of good features of robocopy).
Output is always like:
2015/10/24 01:35:53 ERROR 123 (0x0000007B) Accessing Source Directory C:\Users\..
The filename, directory name, or volume label syntax is incorrect.


So the first part does not depend on the language.

Re: How get data/time independent from localization

Posted: 24 Oct 2015 05:08
by penpen
How about this (if needed Format could be modified):

Code: Select all

@echo off
setlocal enableExtensions enableDelayedExpansion

:: read format from registry
set "variables="iDate" "sDate" "sShortDate" "iTime" "iTimePrefix" "s1159" "s2359" "sTime" "sTimeFormat" "sDecimal""
for %%a in (%variables%) do set "%%~a="
for /F "tokens=1,3" %%a in ('reg query "HKCU\Control Panel\International" ^| findstr "%variables%"') do (
   set "%%~a=%%~b"
   set "variable.%%~a=true"
)
for %%a in (%variables%) do if defined variable.%%~a (
   set "variables=!variables:"%%~a"=!"
   set "variable.%%~a="
)
if not "!variables: =!" == "" for /F "tokens=1,3" %%a in ('reg query "HKU\.DEFAULT\Control Panel\International" ^| findstr "%variables%"') do (
   set "%%~a=%%~b"
   set "variable.%%~a="
)
if "!variables: =!" == "" ( set "variables="
) else echo(@todo: Error: %variables %


:: set date format
:: date[iDate]
set "date[0]=month%sDate%day%sDate%year"
set "date[1]=day%sDate%month%sDate%year"
set "date[2]=year%sDate%month%sDate%day"

for /F "tokens=1-6 delims=%sDate%" %%a in ("!date[%iDate%]!%sDate%%date%") do (
   set "%%~a=%%~d"
   set "%%~b=%%~e"
   set "%%~c=%%~f"
)
for /L %%a in (0, 1, 2) do set "date[%%~a]="


:: set date format
:: time[iTime][iTimePrefix]
set "time[0][0]=hour%sTime%minute%sTime%:second%sDecimal%centisecond timeMarker"
set "time[0][1]=timeMarker hour%sTime%minute%sTime%:second%sDecimal%centisecond"
set "time[1][0]=hour%sTime%minute%sTime%:second%sDecimal%centisecond timeMarker"
set "time[1][1]=hour%sTime%minute%sTime%:second%sDecimal%centisecond timeMarker"

for /F "tokens=1-10 delims=%sTime%%sDecimal% " %%a in ("!time[%iTime%][%iTimePrefix%]! !time!") do (
   set "%%~a=%%~f"
   set "%%~b=%%~g"
   set "%%~c=%%~h"
   set "%%~d=%%~i"
   set "%%~e=%%~j"
)
for /L %%a in (0, 1, 1) do for /L %%b in (0, 1, 1) do set "time[%%~a][%%~b]="


:: remove trailing zeroes
for %%a in ("year" "month" "day" "hour" "minute" "second" "centisecond") do (
   set "%%~a=0000!%%~a!"
   set /A "%%~a=1!%%~a:~-4!-10000"
)

:: convert to 24 if needed: actually not implemented
::    AM    PM     : h:m:s - hh:mm:ss   .
:: s1159 s2359 sTime sTimeFormat sDecimal
:: if "%s1159%" == "%timeMarker%" if %hour%" == "12" set hour...


:: display some info
if "%iTime%" == "0" echo(clock      :   12 hour
if "%iTime%" == "1" echo(clock      :   24 hour

if "%iTimePrefix%" == "0" echo(time marker:    suffix
if "%iTimePrefix%" == "1" echo(time marker:    prefix

echo(

set year
set month
set day
set hour
set minute
set second
set centisecond
if defined timeMarker set timeMarker

endlocal
goto :eof
Works on xp and 8.1.


penpen

Re: How get data/time independent from localization

Posted: 24 Oct 2015 06:13
by mcnd
npocmaka_ wrote: ..., though the info header with day of the week is missing (one of good features of robocopy).


For a locale independed we can use

Code: Select all

set "year="
for /f "tokens=1-6 delims=/: " %%a in ('robocopy "|" . /njh') do if not defined year (
    set "year=%%a" & set "month=%%b" & set "day=%%c"
    set "hour=%%d" & set "min=%%e"   & set "sec=%%f"
   
    rem Zeller's congruence : https://en.wikipedia.org/wiki/Zeller's_congruence
    if %%b lss 3 (set /a "y=%%a-1") else (set "y=%%a")
    set /a "dow=((1%%c %% 100)+(13*((((1%%b %% 100)+9) %% 12 + 3)+1)/5)+(y %% 100)+(y %% 100)/4+(y/100)/4-2*(y/100)) %% 7"

    rem Day correction from Zeller's output (0-Sat to 6-Fri) to ISO-8601 (1-Mon to 7-Sun)
    set /a "dow=(dow+5)%%7+1"
)

echo %year%/%month%/%day% %hour%:%min%:%sec% %dow%


edited: I forgot to include the correction for the initial zeros in day and month and the year correction. Now corrected

Re: How get data/time independent from localization

Posted: 13 Jan 2016 16:58
by Squashman
I am wondering if these are bullet proof.
http://www.commandline.co.uk/cmdfuncs/dandt/#getdate

The author said it stemmed from an old alt.msdos post here:
https://groups.google.com/forum/?hl=en# ... pEtjA07VAJ

Re: How get data/time independent from localization

Posted: 13 Jan 2016 17:22
by dbenham
I only looked at the :GetDate function, and it is definitely NOT locale agnostic. It is highly dependent on the language specific abbreviations used for year, month and day.

Way back when I attempted to provide a platform for handling multiple languages based on that technique: viewtopic.php?f=3&t=1808


Dave Benham

Re: How get data/time independent from localization

Posted: 26 Oct 2016 20:56
by Squashman
Did we ever discuss the WHERE command with the /T option. Is it region independent?

Code: Select all

C:\Users\Squashman>where /T cmd.exe
    233984   10/30/2015    2:17:49 AM  C:\WINDOWS\System32\cmd.exe

Re: How get data/time independent from localization

Posted: 26 Oct 2016 21:01
by dbenham
I'd be willing to bet a tidy sum that WHERE /T date/time format is locale dependent.

Dave Benham