如何在日期上加上一年? [英] How can add one year to a date?

查看:392
本文介绍了如何在日期上加上一年?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为日期加上一年,但是新日期总是错误的.

这就是我在做什么:

I want to add one year to a date but the new date is always wrong.

This is what I am doıng:

newdate = date.Addyears(1);



日期= 2010年1月16日
我希望新日期为:
2011年1月16日
但新日期始终为16.00.2011.

我在这里做错了,我不明白.

谢谢您的回答.



date = 16.01.2010
I want the new date to be:
16.01.2011
but the new date always 16.00.2011.

What am I doing wrong here, I don''t understand.

Thank you for your answer.

推荐答案

为您提供使用标准DateTime操作应该不会有问题;


Providing your using standard DateTime operations there shouldn''t be a problem;


DateTime theDate = DateTime.Now;
DateTime yearInTheFuture = theDate.AddYears(1);


这对我来说很好吗?
DateTime date = new DateTime(2010, 01, 16);
DateTime futureDate = date.AddYears(1);


这篇关于如何在日期上加上一年?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆