यहाँ एक बैच फ़ाइल है कि लगभग एक स्थान-निष्पक्ष तरीके से दिन के सप्ताह, दिन, महीने और वर्ष निकालता है।
एकमात्र लोकेल विशिष्ट बात दिन के सप्ताह की वर्तनी है, शेष लोकल तटस्थ है।
तो अंग्रेजी में, यह गुरुवार के लिए Thu
वापस करेगा, लेकिन डच में do
(डोंडरडाग के लिए) होगा।
:: http://stackoverflow.com/questions/203090/how-to-get-current-datetime-on-windows-command-line-in-a-suitable-format-for-usi
:: Works on any NT/2k machine independent of regional date settings
::
:: 20110103 - adapted by [email protected] for Dutch locale
:: 20110303 - adapted by [email protected] for day-of-week
:: Dutch will get jj as year from echo:^|date, so the '%%c' trick does not work as it will fill 'jj', but we want 'yy'
:: luckily, all countries seem to have year at the end: http://en.wikipedia.org/wiki/Calendar_date
:: set '%%c'=%%k
:: set 'yy'=%%k
::
:: Also, in Dutch, there is a difference between %date% and date/t: the former will not include
:: the day-of-the-week, but the latter will.
:: That means the if "%date%A" LSS "A" trick does not work with %date%, we need a loop
:: to check if the day-of-the-week needs us to take tokens 2-4 in stead of 1-3:
:: if "%date%A" LSS "A" (set toks=1-3) else (set toks=2-4)
:: for /f "tokens=1" %%t in ('date/t') do (...)
::
:: Another difference between Dutch and English is that the Dutch date/t will prepend the day of the week in a lower case 2-letter form.
:: So the LSS "A" trick needs to be replaced with an LSS "a" trick
:: if "%date%A" LSS "A" (set toks=1-3) else (set toks=2-4)
:: if "%%ta" LSS "a" (set toks=1-3) else (set toks=2-4)
::
:: In addition, date will display the current date before the input prompt using dashes
:: in Dutch, but using slashes in English, so there will be two occurances of the outer loop in Dutch
:: and one occurence in English.
:: This skips the first iteration:
:: if "%%a" GEQ "A"
::
:: echo:^|date
:: Huidige datum: ma 03-01-2011
:: Voer de nieuwe datum in: (dd-mm-jj)
:: The current date is: Mon 01/03/2011
:: Enter the new date: (mm-dd-yy)
::
:: date/t
:: ma 03-01-2011
:: Mon 01/03/2011
::
:: The assumption in this batch-file is that echo:^|date will return the date format
:: using either mm and dd or dd and mm in the first two valid tokens on the second line, and the year as the last token.
::
:: The outer loop will get the right tokens, the inner loop assigns the variables depending on the tokens.
:: That will resolve the order of the tokens.
::
@ECHO off
set v_day_of_week=
set v_day=
set v_month=
set v_year=
SETLOCAL ENABLEEXTENSIONS
for /f "tokens=1" %%t in ('date/t') do (
set v_day_of_week=%%t
if "%%ta" LSS "a" (set toks=1-3) else (set toks=2-4)
)
::DEBUG echo toks=%toks%
for /f "tokens=2-4 delims=(-)" %%a in ('echo:^|date') do (
::DEBUG echo first token=%%a
if "%%a" GEQ "A" (
for /f "tokens=%toks% delims=.-/ " %%i in ('date/t') do (
set '%%a'=%%i
set '%%b'=%%j
set 'yy'=%%k
)
)
)
if %'yy'% LSS 100 set 'yy'=20%'yy'%
set Today=%'yy'%-%'mm'%-%'dd'%
ENDLOCAL & SET day_of_week=%v_day_of_week% & SET v_year=%'yy'%& SET v_month=%'mm'%& SET v_day=%'dd'%
ECHO Today is Year: [%V_Year%] Month: [%V_Month%] Day: [%V_Day%]
set datestring=%V_Year%%V_Month%%V_Day%
echo %datestring%
echo day of week=%day_of_week%
:EOF
इसके साथ मजा लें!
--jeroen
स्रोत
2011-03-03 20:17:29
ध्यान दें कि यह उन स्थानों पर काम नहीं करेगा जहां दिनांक विभाजक नहीं है/ – laalto
यह एक विश्वसनीय समाधान नहीं होगा, जब मैं यहां 'दिनांक/टी' का उपयोग करता हूं, तो मुझे केवल एक छोटा सा मिलता है (YYYY-MM-DD), इस प्रकार कोई दिन का नाम नहीं। लोकेशंस के साथ जाता है। यदि यह निर्यात के लिए है (कोई भी आप नहीं है), मैं इस काम पर इरादे के अनुसार शर्त नहीं लगाऊंगा। – Jay