怎么判断这个日期?

hxhyuethoi 2006-03-11 11:01:24
怎么判断这个日期?
日期格式为0601意思是2006年1月
怎么判断它的下一个月和上个月是多少?
0601的数据格式为char(4)
...全文
143 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
nameldw 2006-03-11
  • 打赏
  • 举报
回复
string strDate = "0601";
strDate = strDate + "01";
if("9" == strDate.Substring(0,1))
{
strDate = "19" + strDate;
}
else
{
strDate = "20" + strDate;
}
strDate = strDate.Substring(0, 4) + "-" + strDate.Substring(4, 2) + "-" + strDate.Substring(6);

int LastMonth = Convert.ToDateTime(strDate).AddMonths(-1).Month;
int NextMonth = Convert.ToDateTime(strDate).AddMonths(1).Month;

string strLastMonth = Convert.ToDateTime(strDate).AddMonths(-1).ToString("yyMM");
string strNextMonth = Convert.ToDateTime(strDate).AddMonths(1).ToString("yyMM");
hxhyuethoi 2006-03-11
  • 打赏
  • 举报
回复
上个月 (int)01 - 1;
那应该是0512啊
independently 2006-03-11
  • 打赏
  • 举报
回复
把“01”转换为整形,再进行判断
humin1906 2006-03-11
  • 打赏
  • 举报
回复
0601 分解成 06 01。
上个月 (int)01 - 1;
下个月 01 + 1;

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧