How get data/time independent from localization

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How get data/time independent from localization

#76 Post by aGerman » 12 Jul 2015 06:03

The German translations are
Day - Tag
Month - Monat
Year - Jahr
and yes, abbreviations like TT, MM and JJ are commonly used. The MUI conception of Windows takes care that those German abbreviations will appear in their system programs, e.g.

Code: Select all

C:\>date
Aktuelles Datum: 12.07.2015
Geben Sie das neue Datum ein: (TT-MM-JJ)

But that's not a valid point here because the strings "YYYY=", "DD=", etc. are (hard-coded) string literals in Antonio's tools. For that reason they will not change :wink:

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: How get data/time independent from localization

#77 Post by Aacini » 12 Jul 2015 07:21

Yes. The output is always the same in all computers. Is the input format the one that must be provided in locale format. This point allows to use StdDate program with the file dates shown by DIR command or by %~T... FOR modifier to get the date values from files. This means that a Batch file that use this feature will get the same result in all computers...

Antonio

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

Re: How get data/time independent from localization

#78 Post by foxidrive » 12 Jul 2015 09:47

Aacini wrote:Yes. The output is always the same in all computers. Is the input format the one that must be provided in locale format. This point allows to use StdDate program with the file dates shown by DIR command or by %~T... FOR modifier to get the date values from files. This means that a Batch file that use this feature will get the same result in all computers...

Antonio


That's clever Antonio.

npocmaka_
Posts: 512
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: How get data/time independent from localization

#79 Post by npocmaka_ » 22 Oct 2015 10:17

(Can anybody else confirm - I've used windows 10 and windows 7) Typeperf and Logman logs the date and time always in format MM/dd/YYYY hh:mm:ss.ttt.

So :

Code: Select all

@echo off
setlocal
set "timeline="
for /f "skip=2 delims=," %%# in ('typeperf "\Processor(_Total)\%% Processor Time" -si 0 -sc 1') do (
   
   if not defined timeline (
   set "timeline=%%#"
   echo %%#
   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%%hour%%minute%%sec%%ms%
endlocal

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How get data/time independent from localization

#80 Post by aGerman » 22 Oct 2015 11:05

What I can confirm ist that the time format of typeperf is the same for me (Win7). But I can't confirm that this is a localization-/language-independent way. The corresponding German command line would be

Code: Select all

typeperf "\Prozessor(*)\Prozessorzeit (%%)" -si 0 -sc 1

That means your posted code would never work for me (actually I'm surprised that it works for you because I didn't expect you're living in an English speaking environment).

I wasn't able to find a similar way using logman. Can you tell us what you tried out?

Regards
aGerman

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

Re: How get data/time independent from localization

#81 Post by Squashman » 22 Oct 2015 11:21

npocmaka_ wrote:(Can anybody else confirm - I've used windows 10 and windows 7) Typeperf and Logman logs the date and time always in format MM/dd/YYYY hh:mm:ss.ttt.

We started talking about typeperf in this thread already starting at this post.
viewtopic.php?p=41976#p41976

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

Re: How get data/time independent from localization

#82 Post by Squashman » 22 Oct 2015 11:43

I am betting LOGMAN has the same issue as TYPEPERF

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

Re: How get data/time independent from localization

#83 Post by Squashman » 22 Oct 2015 12:03

If the GUID's are the same for each language then maybe you could.

Code: Select all

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

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: How get data/time independent from localization

#84 Post by aGerman » 22 Oct 2015 12:20

Squashman wrote:We started talking about typeperf in this thread already starting at this post.

You're right. I didn't even remember it :oops:

What command line did you execute to get the output that you quoted in your latest response?

npocmaka_
Posts: 512
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: How get data/time independent from localization

#85 Post by npocmaka_ » 22 Oct 2015 12:25

Squashman wrote:
npocmaka_ wrote:(Can anybody else confirm - I've used windows 10 and windows 7) Typeperf and Logman logs the date and time always in format MM/dd/YYYY hh:mm:ss.ttt.

We started talking about typeperf in this thread already starting at this post.
viewtopic.php?p=41976#p41976



oh :!: I'm an idiot...

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

Re: How get data/time independent from localization

#86 Post by Squashman » 22 Oct 2015 12:34

aGerman wrote:What command line did you execute to get the output that you quoted in your latest response?

Code: Select all

logman query providers
logman query providers {36C23E18-0E66-11D9-BBEB-505054503030}
logman query providers Microsoft-Windows-Diagnostics-Networking

npocmaka_
Posts: 512
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: How get data/time independent from localization

#87 Post by npocmaka_ » 22 Oct 2015 13:11

typeperf -q and getting random performance counter is a possible way to workaround the issue with the localization



other is using name like (faster)

typeperf "\*\*" -si 0 -sc 1

or

typeperf "\*(*)\*" -si 0 -sc 1
typeperf "\*%%\*%%" -si 0 -sc 1

(are these wildcards? - I need to experiment with these to find the least verbose query)

first one seems to be faster

though both will give a latency and precious seconds can be lost if they matter (btw -si argument accepts 0 which makes using it a little bit faster)

npocmaka_
Posts: 512
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: How get data/time independent from localization

#88 Post by npocmaka_ » 22 Oct 2015 13:18

Are these performance counter translated (the first part of the name for the last * can be used):

IPv6
IPv4
TCPv6
TCPv4
UDPv4
UDPv6

?

npocmaka_
Posts: 512
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: How get data/time independent from localization

#89 Post by npocmaka_ » 22 Oct 2015 13:37

The fastest query with no specific strings I've found

typeperf "\*(%)\1" -si 0 -sc 1 (~424 bytes when redirected to a file ) fills the data with "-1" so I don't know exaclty is queried.


edit
but does not work on XP

this works but is twice as size:

typeperf "\*(%)\*(%)" -si 0 -sc 1

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

Re: How get data/time independent from localization

#90 Post by Squashman » 22 Oct 2015 13:58

About a 2 to 3 second delay for me.

Code: Select all

H:\>echo %time% &for /F "tokens=1,2,3,4,5,6 delims=/:. " %G in ('typeperf "\*(%)\1" -si 0 -sc 1 ^|find "/"') do @echo %~I%~G%~H_%~J%~K%~L
14:57:44.21
20151022_145746

Post Reply