日期的使用
-
介绍
在侦测类别中,创益编程游乐场新增了一些积木,用于计算日期。
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/a99d0717-3e91-4519-959f-1683479ada42.png" width="500" style="">
积木:“日期( )”
你可以用积木“日期( )”来表示一个日期:
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/ce153b63-343d-4020-807e-4e8231dd5d57.png" width="100" style="filter: drop-shadow(0.35rem 0.35rem 0.4rem rgba(0, 0, 0, 0.5));">
输入框可接受2种格式:
- 月月/日日/年年年年:例如“11/05/2018”
- 年年年年月月日日:例如“20181105”
这2种格式表示同一个日期。你可以点击该积木进行验证:
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/5e2ac957-9052-4e19-a022-1c16524c15b1.gif" width="700" style="">
日期计算
可以用运算积木做基本的日期计算。
例如,你可以用加减运算积木计算某个日期多少天前的日期或多少天后的日期:
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/90d31057-b690-49a4-b3ce-4dcc6b194cb8.gif" width="700" style="">
还可以用相减积木“-”计算2个日期相差几天:
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/a5a5e500-be82-41bc-810d-2b32cfd86b73.gif" width="500" style="">
获取日期的星期几/日/月份/年份
这4个报表积木把日期积木作为输入值,然后告诉我们该日期的星期几/日/月份/年份:
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/bfd2918b-4432-4546-b75d-005e4355ead5.gif" width="700" style="">
注意“星期几”,取值1表示是星期一,取值7表示是星期天。
范例——下个星期一
例如,假如我们想知道2023年8月1日之后的第一个星期一,计算该日期分3步:
- 找出日期20230801是星期几,为星期二(值为2);
- 计算离下一个星期一还有多少天,为6天(8-2);
- 计算20230801六天后的日期,为20230807。
下面是每一步计算所用到的积木:
https://cdncreaticodecom.b-cdn.net/scratch-gui-projects/forum/799874ed-4fc9-4728-ab03-d91e49661ce0.gif" width="700" style="">
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login