开发者

VisualStudio: translating a build version to a calendar date

开发者 https://www.devze.com 2023-01-20 21:47 出处:网络
I know that the version string generated by Vi开发者_StackOverflow社区sual Studio is based on the date/time of when the build was run. Given the partial version string \"3856.24352\" generated by Visu

I know that the version string generated by Vi开发者_StackOverflow社区sual 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?


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).

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);

This will give you a DateTime representing when the build was produced (which for your example is 23rd July, 2010 at 13:31:44).


Here is a simple javascript tool for converting .Net version into a date:

Sample Input:
1.0.7769.27451

Sample Output:
5/9/2021, 3:15:02 PM

function convertBuildNumberToDate()
{
  var buildString = document.getElementById("input").value.split(".");
  var buildNumber = Number(buildString[2]);
  var revision = Number(buildString[3]);

  var date = new Date(2000, 1, 1);
  date.setDate(buildNumber);
  date.setSeconds(revision * 2);

  var output = date.toLocaleString();
  document.getElementById("output").innerHTML = output;
}
Build Number:
<br />
<input id="input" value="1.0.7769.27451" />
<button onclick="convertBuildNumberToDate()">Convert</button>

<br />
<br />

Build Date:
<br />
<div id="output"></div>

0

精彩评论

暂无评论...
验证码 换一张
取 消