An problem about date(怎么就放在动态规划里面呢。。。)

日期转星期算法
本文介绍两种将具体日期转换为对应星期的方法:一种是通过预先计算并存储每年1月1日对应的星期,结合日期计算得到结果;另一种是使用基姆拉尔森计算公式直接计算。涉及C++编程实现。

An problem about date

时间限制:2000 ms | 内存限制:65535 KB
难度:2
描述

acm的iphxer经常忘记某天是星期几,但是他记那天的具体日期,他希望你能写个程序帮帮他。

输入
每行有三个整数 year,month,day,日期在1600年1月1日到9600年1月1日之间;
输出
输出对应的星期,用一个整数表示;(星期一到星期六用1-6表示,星期日用0表示)
样例输入
2011 3 6
1949 10 1
2011 4 1
1945 8 15
样例输出
0
6
5
3
my answer:
// 方法一
 
#include<iostream>
#include<stdio.h>
#include<cmath>
#include<stdlib.h>

// 判断是否是闰年 
using namespace std;
bool run(int y)
{
	if(y%400 == 0 || y%4==0&&y%100 != 0) return true;
	else return false;
}
int a[12000];     // 打表 存放每年的1 月1日是星期几 
int b[13]={0,31,0,31,30,31,30,31,31,30,31,30,31};  // 月份天数 
int main()
{
	a[3615]=4;
	// before 2015
	for(int i = 3614; i >=3000; i --)
	{
		a[i]=a[i+1]-365%7;
		if(run(i-1600)) a[i]--;
		if(a[i]<=0) a[i]=7+a[i];
	}
	// after 2015
	for(int i =3616 ; i <= 12000; i ++)
	{
		 a[i]=365%7+a[i-1];
		 if(run(i-1600-1))  a[i]++;
		 if(a[i]==8)
		    a[i]=1; 
	}
	int year, month,day;
	while(scanf("%d%d%d",&year,&month,&day)==3)
	{
		
		int countday = day-1, data = 0;
		if(month > 3)
		 {
			for(int i = 1; i <month; i ++)
				countday+=b[i];
			if(run(year)) countday+=29;
			else countday+=28;
		}else {
			for(int i = 1; i < month; i ++)
			   countday+=b[i];
		}
		data = a[year+1600]+countday%7;
	    printf("%d\n",data%7);
	}
	return 0;
}

// 方法二 基姆拉尔森计算公式 ,竟然有公式<img alt="尴尬" src="http://static.blog.youkuaiyun.com/xheditor/xheditor_emot/default/awkward.gif" />!!!!
/*

 #include<iostream>
 #include<stdio.h>
 using namespace std;
 int weekday[]={0,1,2,3,4,5,6};
 int main()
 {
 	int year,month,day;
 	while(scanf("%d%d%d",&year,&month,&day)==3)
 	{
 		if(month == 1 || month == 2)
 		{
 			 month=(month == 1?13:14);
			 year--;
 		}
		int data=(day+2*month+3*(month+1)/5+year+year/4-year/100+year/400+1)%7;
		printf("%d\n",data);
 	}
 
 	return 0;
 }
 */


<think>We are given a reference about a RangeDate default value issue in JeecgBoot. The reference mentions that there is a known issue in the current version and a fix will come in a future version. Until then, a temporary workaround is needed. However, the user's specific question is: "如何在jeecgboot中为RangeDate设置默认值" (How to set the default value for RangeDate in JeecgBoot). We note that the reference [^1] states that there's a problem in the current version and a temporary fix is available until the official fix. Since the user is asking for the method to set the default value, we should provide the way to do it, even if it's a temporary solution. Steps to set default values for RangeDate in JeecgBoot: 1. In the form component (usually in the Vue file), locate the RangePicker (the component for RangeDate). 2. Use the `v-model` or `value` attribute to bind the default value. However, note that the issue might be that the default value isn't being set correctly in the current version. 3. According to the reference, there might be a known issue. Therefore, we can try a temporary solution until the fix is released. One common way to set the default value for a RangePicker (using Ant Design Vue, which is used in JeecgBoot) is: ```vue <template> <a-range-picker v-model:value="dateRange" /> </template> <script> import { ref } from 'vue'; export default { setup() { // Set default value to yesterday and today, for example const yesterday = new Date(); yesterday.setDate(yesterday.getDate() - 1); const today = new Date(); const dateRange = ref([yesterday, today]); return { dateRange }; } }; </script> ``` Alternatively, in the options of the JEditableTable or form schema, you might set the default value in the column definition. Example in a JEditableTable column: ```js { title: '日期范围', key: 'dateRange', type: 'date', range: true, // indicates it's a range picker defaultValue: [moment().subtract(1, 'days'), moment()] // if using moment.js } ``` But note: The reference [^1] indicates that there is an issue in the current version. So if the above doesn't work, we can try setting the value in the created/mounted hook. Temporary workaround (if the default value doesn't show up): We can set the value of the range picker in the `mounted` lifecycle hook by directly setting the form model or the component's value. Example: ```vue <script> import { ref, onMounted } from 'vue'; export default { setup() { const dateRange = ref([]); onMounted(() => { // Wait for the next tick to ensure the component is rendered setTimeout(() => { const yesterday = new Date(); yesterday.setDate(yesterday.getDate() - 1); const today = new Date(); dateRange.value = [yesterday, today]; }, 0); }); return { dateRange }; } }; </script> ``` Alternatively, if using Options API: ```vue <script> export default { data() { return { dateRange: [] }; }, mounted() { const yesterday = new Date(); yesterday.setDate(yesterday.getDate() - 1); const today = new Date(); this.dateRange = [yesterday, today]; } }; </script> ``` Note: The use of `setTimeout` might be necessary if the component isn't ready at the exact moment of `mounted`. However, the exact approach may depend on the context (like if it's in a form or a table). Also, note that the user might be using the older version of Ant Design (v2) in their JeecgBoot. If the above does not work, another temporary solution might be to set the default value in the model of the form when initializing the form. For example, in the form model: ```js this.form.setFieldsValue({ dateRange: [moment().subtract(1, 'days'), moment()] }); ``` But note: This might be done in the `created` or `mounted` hook, but after the form has been initialized. Since the issue is known and a fix is coming, the user should also be advised to upgrade when the fix is available. Therefore, the answer should include: - The standard way of setting the default value (which might be broken in the current version) - A temporary workaround (using the mounted hook or setTimeout) - A note about the upcoming fix and the need to upgrade. Let's structure the answer accordingly. </think>在 JeecgBoot 中为 RangeDate(日期范围选择器)设置默认值,可以通过以下步骤实现。根据引用内容[^1],当前版本可能存在已知问题,官方将在后续版本修复,以下是推荐的临时解决方案: ### 标准设置方法(Vue3 + Ant Design Vue 语法) ```vue <template> <!-- 在表单组件中使用 --> <a-form-item label="日期范围" name="dateRange"> <a-range-picker v-model:value="modelRef.dateRange" format="YYYY-MM-DD" /> </a-form-item> </template> <script setup> import { reactive } from 'vue'; import { Moment } from 'moment'; const modelRef = reactive({ // 设置默认值为最近7天 dateRange: [ moment().subtract(7, 'days'), moment() ] }); </script> ``` ### 临时解决方案(针对当前版本的已知问题) 1. **初始化时动态赋值** ```vue <script setup> import { onMounted } from 'vue'; const setDefaultRange = () => { // 获取组件实例 const rangePicker = document.querySelector('.ant-picker-input input'); if(rangePicker) { // 设置默认值(示例:当天日期) rangePicker.value = `${moment().format('YYYY-MM-DD')} ~ ${moment().format('YYYY-MM-DD')}`; } } onMounted(() => { setTimeout(setDefaultRange, 300); // 延迟确保DOM加载 }); </script> ``` 2. **后端接口预处理** 在返回表单数据的接口中,直接返回预设值: ```json // 接口响应示例 { "dateRange": ["2023-11-01", "2023-11-07"] } ``` ### 注意事项 1. 使用 `moment` 库处理日期格式,需先安装: ```bash npm install moment ``` 2. 当前版本(引用[^1])存在默认值可能失效的问题: - 推荐升级到最新版本(关注[JeecgBoot GitHub](https://github.com/jeecgboot/jeecg-boot)) - 临时方案中建议增加300ms延迟确保组件渲染完成 - 复杂场景可改用 `:default-value="[...]"` 属性尝试 3. 持久化存储建议: ```javascript // 从localStorage读取上次选择 const lastRange = JSON.parse(localStorage.getItem('lastDateRange')); modelRef.dateRange = lastRange || [moment(), moment()]; ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值