VisualStudio:将生成版本翻译为日历日期 [英] VisualStudio: translating a build version to a calendar date
问题描述
我知道Visual Studio生成的版本字符串是基于运行构建的日期/时间的.给定Visual Studio生成的部分版本字符串"3856.24352",我如何将其转换为生成该版本的日历天?
I know that the version string generated by Visual Studio is based on the date/time of when the build was run. Given the partial version string "3856.24352" generated by Visual Studio, how can I translate that to the calendar day on which that build took place?
推荐答案
完整版本字符串的格式为 major.minor.build.revision . build 部分是自2000年1月1日以来的天数.修订部分是自午夜以来的秒数除以2(请参阅此处了解更多信息).
The full version string is in the format major.minor.build.revision. The build part is the number of days since 1st January, 2000. The revision part is the number of seconds since midnight divided by 2 (see here for more info).
假设您的版本字符串是自动递增类型,并且您已使用 build.revision 部分,则可以使用以下命令将其转换为日期:
Assuming that your version strings are the auto-incrementing type, and that you have taken the build.revision part, you can turn it back into the date using:
string buildRevision = "3856.24352";
string[] parts = buildRevision.Split('.');
int build = int.Parse(parts[0]);
int revision = int.Parse(parts[1]);
DateTime dateTimeOfBuild = new DateTime(2000, 1, 1)
+ new TimeSpan(build, 0, 0, 0)
+ TimeSpan.FromSeconds(revision * 2);
这将为您提供一个DateTime
代表构建的生成时间(例如,2010年7月23日,位于13:31:44).
This will give you a DateTime
representing when the build was produced (which for your example is 23rd July, 2010 at 13:31:44).
这篇关于VisualStudio:将生成版本翻译为日历日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!