如果我输入
DateString[{2011, 2, 29, 0, 0, 0}, {"DayName"}]
它给出了 "Tuesday"

并且,
DateString[{2011, 2, 29, 0, 0, 0}, {"DayName"}]DateString[{2011, 3, 1, 0, 0, 0}, {"DayName"}]

最佳答案

Needs["Calendar`"];
myDay[x_List] := DateString[x, {"DayName"}] /; DateQ[x]

myDay[{2000, 1, 1}]
->"Saturday"

myDay[{2000, 13, 13}]
->myDay[{2000, 13, 13}]

当然,如果您想,您可以抛出一条消息(或 Abort[] 或其他):
Needs["Calendar`"];
Clear@myDay;
myDay[x_] /; If[DateQ[x], True, Message[myDay::nodate, x]; False] :=
                                                       DateString[x, {"DayName"}]
myDay::nodate = "The argument `1` is not a valid date.";

关于wolfram-mathematica - Mathematica 中的 DateString 有问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5306658/

10-11 06:36