|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『楼 主』:
从日期判断星期
使用 LLM 解释/回答一下
比如20060110
如何通过以上日期判断是星期几?
For example, 20060110
How to determine what day of the week it is based on the above date?
|
|
2007-2-6 03:11 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
提供一个思路:先确定一个已经知道是星期几的日期,然后计算20060110和那个日期相差多少天,然后用差值来除以7,取余数——问题的关键在于计算两个日期的差值,这又转化为以前那个经典老话题:某一日期的N天前是哪一天?
Here's an idea: First, determine a date for which you already know what day of the week it is. Then calculate the difference in days between 20060110 and that date. Then divide the difference by 7 and take the remainder - the key point is calculating the difference between the two dates, which is transformed back to the classic old topic: What day of the week was N days before a certain date?
|

尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2007-2-6 03:24 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
取得n天前的日期我会,但就是不会计算星期
比如今天是20070205 星期一 n天前的日期是20061210
该怎么计算呢?
20070205减20061210 怎么减呢?
I can calculate the date n days ago, but just can't calculate the day of the week.
For example, today is 20070205 Monday, the date n days ago is 20061210.
How to calculate it?
How to subtract 20061210 from 20070205?
|
|
2007-2-6 05:22 |
|
|
everest79
金牌会员
      一叶枝头,万树皆春
积分 2564
发帖 1127
注册 2006-12-25
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
版主说的不错,你首先得有一个参照物,剩下的就是将日期间距转换为10进制的天数并减去7-参照星期,然后再用7除求余
The moderator's statement is quite right. First of all, you need to have a reference object. The rest is to convert the date interval into decimal days, subtract 7 minus the reference week, and then divide by 7 to find the remainder.
|
|
2007-2-6 08:26 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
再来一个另类星期几查询:)
- @ echo off && setlocal
- :: Redtek.2006 bbs.cn-dos.net 查询某年/月/日是星期几
- set /p setDate=请输入要查询的日期:(格式:年-月-日)
- :: 备份当前日期并设置新日期
- for /f %%i in ('date/t') do set "当天日期备份=%%i"
- echo %setDate%|date >nul
- :: 显示查询日期并恢复当前日期为备份日期
- echo. && echo 您要查询的日期详细信息为: %date% ] && echo.
- echo %当天日期备份%|date >nul
- Pause
Redtek@sweetmeet.com发表于: 2007-02-05 20:26
注: 如果是服务器等与日期相连紧密的计算机请勿使用此代码。
因实现原理是先备份当前日期,再设置指定日期,利用系统%date%得到星期几,然后再还原计算前的日期。
在计算机上安装了有些对日期敏感的程序,如:进行Java开发的 JCreator pro 等敏感软件,如果日期被更改为过去时,就是再改回来其已经作废。
Another alternative day-of-the-week query: )
- @ echo off && setlocal
- :: Redtek.2006 bbs.cn-dos.net Query what day of the week a certain year/month/day is
- set /p setDate=Please enter the date to query: (Format: year-month-day)
- :: Backup current date and set new date
- for /f %%i in ('date/t') do set "Current date backup=%%i"
- echo %setDate%|date >nul
- :: Display the queried date and restore the current date to the backup date
- echo. && echo The detailed information of the date you want to query is: %date% ] && echo.
- echo %Current date backup%|date >nul
- Pause
Redtek@sweetmeet.comPosted on: 2007-02-05 20:26
Note: Do not use this code on computers such as servers that are closely connected to the date.
Because the implementation principle is to first back up the current date, then set the specified date, use the system %date% to get the day of the week, and then restore the date before the calculation.
If some date-sensitive programs are installed on the computer, such as: JCreator pro for Java development and other sensitive software, if the date is changed to the past, even if it is changed back, it has become invalid.
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2007-2-6 09:23 |
|
|
anqing
高级用户
   
积分 859
发帖 413
注册 2006-8-14
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
楼上兄,一个字,“赞”
Brother upstairs, just one word, "Like"
|
|
2007-2-6 09:38 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
利用刚学会的VBS
@echo off
for %%n in (week1-日 week2-一 week3-二 week4-三 week5-四 week6-五 week7-六) do set Tmp$=%%n&&call set %%Tmp$:-==%%
:loop
cls
echo.
set input=
set /p input= 请输入日期(格式: 2007/1/1):
if not defined input exit
echo.
>tmp.vbs echo wscript.echo weekday(#%input%#)
for /f "tokens=* delims=-" %%i in ('"cscript //nologo tmp.vbs"') do call echo 星期%%week%%i%%
del tmp.vbs
echo.
pause
goto loop
加上一个根据 9 楼修改的:
@echo off
for %%n in (week1-日 week2-一 week3-二 week4-三 week5-四 week6-五 week7-六) do set Tmp$=%%n&&call set %%Tmp$:-==%%
:loop
cls
echo.
set input=
set /p input= 请输入日期(格式: 20070101):
if not defined input exit
echo.
>tmp.vbs echo wscript.echo Weekday(CDate("%input:~0,4%-%input:~4,2%-%input:~6,2%"))
for /f "tokens=* delims=-" %%i in ('"cscript //nologo tmp.vbs"') do call echo 星期%%week%%i%%
del tmp.vbs
echo.
pause
goto loop
Last edited by zh159 on 2007-2-6 at 03:07 PM ]
Using the newly learned VBS
@echo off
for %%n in (week1-日 week2-一 week3-二 week4-三 week5-四 week6-五 week7-六) do set Tmp$=%%n&&call set %%Tmp$:-==%%
:loop
cls
echo.
set input=
set /p input= Please enter the date (format: 2007/1/1):
if not defined input exit
echo.
>tmp.vbs echo wscript.echo weekday(#%input%#)
for /f "tokens=* delims=-" %%i in ('"cscript //nologo tmp.vbs"') do call echo Week %%week%%i%%
del tmp.vbs
echo.
pause
goto loop
Add one modified according to floor 9:
@echo off
for %%n in (week1-日 week2-一 week3-二 week4-三 week5-四 week6-五 week7-六) do set Tmp$=%%n&&call set %%Tmp$:-==%%
:loop
cls
echo.
set input=
set /p input= Please enter the date (format: 20070101):
if not defined input exit
echo.
>tmp.vbs echo wscript.echo Weekday(CDate("%input:~0,4%-%input:~4,2%-%input:~6,2%"))
for /f "tokens=* delims=-" %%i in ('"cscript //nologo tmp.vbs"') do call echo Week %%week%%i%%
del tmp.vbs
echo.
pause
goto loop
Last edited by zh159 on 2007-2-6 at 03:07 PM ]
|
|
2007-2-6 14:39 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
5楼的方法确实不错,不过要更改系统时间,似觉总有点不够完美,各位还有什么高招吗?
The method on the 5th floor is indeed good, but it seems a bit less perfect to change the system time. Do you all have any other good ideas?
|
|
2007-2-6 16:29 |
|
|
112183883
初级用户
 
积分 128
发帖 31
注册 2006-10-23
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
何不用VBS呢?
<script language="vbscript">
<!--
MsgBox Weekday(CDate("2006-01-10")-1)
-->
</script>
Why not use VBS?
<script language="vbscript">
<!--
MsgBox Weekday(CDate("2006-01-10")-1)
-->
</script>
|
|
2007-2-6 17:55 |
|
|
NaturalJ0
银牌会员
    
积分 1181
发帖 533
注册 2006-8-14
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
记得小时候奥数有个公式的,可以再查下。
I remember there was a formula in the Olympiad in Mathematics when I was a child, and I can check it again.
|
|
2007-2-6 21:16 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
取得两个日期的差已经解决,现在的问题是怎么判断星期?
//比如 已知2007/02/08/星期四 如何确定 18天前的星期呢?
就是如何将当前星期减1或2..........?
Last edited by 26933062 on 2007-2-8 at 03:47 AM ]
The problem of getting the difference between two dates has been solved. Now the problem is how to determine the day of the week?
//For example, given Thursday, February 8, 2007, how to determine the day of the week 18 days ago?
That is, how to subtract 1 or 2 from the current day of the week...?
Last edited by 26933062 on 2007-2-8 at 03:47 AM ]
|
|
2007-2-8 16:40 |
|
|
anqing
高级用户
   
积分 859
发帖 413
注册 2006-8-14
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
帮你顶一下,越来越有难度了
Give you a boost, it's getting more challenging
|
|
2007-2-8 22:01 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
Originally posted by 26933062 at 2007-2-8 03:40:
取得两个日期的差已经解决,现在的问题是怎么判断星期?
//比如 已知2007/02/08/星期四 如何确定 18天前的星期呢?
就是如何将当前星期减1或2..........?
...
@echo off
for %%n in (week1-日 week2-一 week3-二 week4-三 week5-四 week6-五 week7-六) do set Tmp$=%%n&&call set %%Tmp$:-==%%
:loop
cls
echo.
set input=
set week=+0
set /p input= 请输入日期(格式: 20070101):
if not defined input exit
set /p week= 请输入间隔天数(格式: +8(-8),默认为 0):
echo.
>tmp.vbs echo wscript.echo Weekday(CDate("%input:~0,4%-%input:~4,2%-%input:~6,2%")%week%)
for /f "tokens=* delims=-" %%i in ('"cscript //nologo tmp.vbs"') do call echo 星期%%week%%i%%
del tmp.vbs
echo.
pause
goto loop
Originally posted by 26933062 at 2007-2-8 03:40:
The difference between two dates has been solved. Now the problem is how to determine the day of the week?
// For example, given 2007/02/08/Thursday, how to determine the day of the week 18 days ago?
That is, how to subtract 1 or 2 from the current day of the week..........?
...
@echo off
for %%n in (week1-日 week2-一 week3-二 week4-三 week5-四 week6-五 week7-六) do set Tmp$=%%n&&call set %%Tmp$:-==%%
:loop
cls
echo.
set input=
set week=+0
set /p input= Please enter the date (format: 20070101):
if not defined input exit
set /p week= Please enter the number of days interval (format: +8(-8), default is 0):
echo.
>tmp.vbs echo wscript.echo Weekday(CDate("%input:~0,4%-%input:~4,2%-%input:~6,2%")%week%)
for /f "tokens=* delims=-" %%i in ('"cscript //nologo tmp.vbs"') do call echo Day of the week%%week%%i%%
del tmp.vbs
echo.
pause
goto loop
|
|
2007-2-9 05:23 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
MsgBox WeekdayName(Weekday(CDate(Now)))
MsgBox WeekdayName(Weekday(CDate(Now)))
|
|
2007-2-9 06:00 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
借楼上的:
MsgBox WeekdayName(Weekday(CDate(Now) -18))
+-天数
@echo off
:loop
cls
echo.
set input=
set week=+0
set /p input= 请输入日期(格式: 20070101):
if not defined input exit
set /p week= 请输入间隔天数(格式: +8(-8),默认为 0):
echo.
>tmp.vbs echo wscript.echo WeekdayName(Weekday(CDate("%input:~0,4%-%input:~4,2%-%input:~6,2%")%week%))
for /f %%i in ('"cscript //nologo tmp.vbs"') do call echo %%i
del tmp.vbs
echo.
pause
goto loop
Last edited by zh159 on 2007-2-8 at 06:42 PM ]
Borrowing from the above:
MsgBox WeekdayName(Weekday(CDate(Now)-18))
+ - number of days
@echo off
:loop
cls
echo.
set input=
set week=+0
set /p input= Please enter the date (format: 20070101):
if not defined input exit
set /p week= Please enter the number of days to interval (format: +8(-8), default is 0):
echo.
>tmp.vbs echo wscript.echo WeekdayName(Weekday(CDate("%input:~0,4%-%input:~4,2%-%input:~6,2%")%week%))
for /f %%i in ('"cscript //nologo tmp.vbs"') do call echo %%i
del tmp.vbs
echo.
pause
goto loop
Last edited by zh159 on 2007-2-8 at 06:42 PM ]
|
|
2007-2-9 06:05 |
|