如何将输入的天数转换为VB.NET中的年,月和日数 [英] How do I convert inputted days to number of years, months, and days in VB.NET

查看:132
本文介绍了如何将输入的天数转换为VB.NET中的年,月和日数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将输入的天数转换为VB.net中的年,月和日数



我尝试过:



我试过这样做



年/ 365

月MOD 12

天/ 7

How do I convert inputted days to number of years,months, and days in VB.net

What I have tried:

I tried to do this

Years / 365
Months MOD 12
Days / 7

推荐答案

差不多,你不能。

好​​几天 X不会转换为a年,b个月和c天,因为月份和年份的长度不一样:年份可以是365或366天,一个月可以是28,29,30或31天长。并且b个月取决于您在当年开始工作的地方!

这就是为什么Timespan类不处理任何大于天的单位:因为所有较大的单位都需要开始日期 从中工作。

如果你正在谈论从开始日期和几天开始计算日期,那很简单:DateTime.AddDays会这样做。

但是如果你想要什么更复杂的是,你需要仔细考虑你期望输入的内容,以及你期望得到的内容!



这可以帮助你:使用Age:它与TimeSpan不同! [ ^ ]或至少为您提供思考的背景(它在C#中,但在线转换器会为您翻译)
Pretty much, you can't.
A number of days "X" does not translate to "a years, b months, and c days" because months and years are not all the same length: years can be 365 or 366 days long, a month can be 28, 29, 30, or 31 days long. And "b months" depends on where in the current year you start working from!
This is why the Timespan class does not deal with any unit larger than days: because all larger units need a "start date" to work from.
If you are talking about working out a date from a start date and a number of days, that's simple: DateTime.AddDays will do that.
But if you want anything more complex, you need to think pretty carefully about exactly what you expect to input, and exactly what you expect to get!

This may help you: Working with Age: it's not the same as a TimeSpan![^] or at least give you background to think about (it's in C#, but the online converters will translate it for you)


这篇关于如何将输入的天数转换为VB.NET中的年,月和日数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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