Jump to content

How do I get the date/time?


Recommended Posts

Hmmm. Interesting, never seen those methods before.

The current gametime I've always used is Planatarium.GetUniversalTime(), that returns a double that is seconds since game start.

However, I've never had to make that human readable, I'm not sure how you would go about converting it. Maybe KSPUtil.GetDateFromUI( Planetarium.GetUniversalTime()); ?

D.

Link to comment
Share on other sites

Hmmm. Interesting, never seen those methods before.

The current gametime I've always used is Planatarium.GetUniversalTime(), that returns a double that is seconds since game start.

However, I've never had to make that human readable, I'm not sure how you would go about converting it. Maybe KSPUtil.GetDateFromUI( Planetarium.GetUniversalTime()); ?

D.

I will try that, hopefully it will work.

Link to comment
Share on other sites

  • 1 month later...

Perhaps I'm misunderstanding something obvious here but when I try to use KSPUtil.GetDateFromUT(Planetarium.GetUniversalTime()); I'm getting an error: "The best overloaded method match for 'KSPUtil.GetDateFromUT(int)' has some invalid arguments" -> "Argument 1: cannot convert from 'double' to 'int'"

My code looks like this:

double currentUniversalTime = KSPUtil.GetDateFromUT(Planetarium.GetUniversalTime());

Link to comment
Share on other sites

Planetarium.GetUniversalTime() returns a Double, so you would have to cast/convert it as an Int for the GetDateFromUT function.

Although what GetDateFromUT is gonna return I dont know as Planetarium.GetUniversalTime() is the current Universal Time. If you are looking for something that converts UT to year and day I can share a timelibrary I worked on recently that I think is ready. But cant link it till I get home

Link to comment
Share on other sites

Planetarium.GetUniversalTime() returns a Double, so you would have to cast/convert it as an Int for the GetDateFromUT function.

Although what GetDateFromUT is gonna return I dont know as Planetarium.GetUniversalTime() is the current Universal Time. If you are looking for something that converts UT to year and day I can share a timelibrary I worked on recently that I think is ready. But cant link it till I get home

Cool, so I'll just mess about with converting the function then. Also, if you can upload the timelibrary I'll definitely check it out. Thanks.

Link to comment
Share on other sites

I have it in place in a dev branch of my TWP mod. The two files you need are:

https://github.com/TriggerAu/TransferWindowPlanner/blob/feature/timelibrary/TransferWindowPlanner/FrameworkExt/KSPDateTime.cs

https://github.com/TriggerAu/TransferWindowPlanner/blob/feature/timelibrary/TransferWindowPlanner/FrameworkExt/KSPTimeSpan.cs

Just put these in your project and add using KSPPluginFramework; and you shoudl have them accessible

Basically these are KSP versions of the c# datetime and timespan structs. So some simple examples are:

KSPDateTime dt = new KSPDateTime(301.123);

This will give you a Datetime of year 1, Day 1, Hour 0, Minute 5, Second 1, millisecond 123 - each attribute (Hour, Day, etc is a property you can read)

You can do add/deletes/compares like the DateTime ones too


dt = dt.AddDays(3);
dt = dt.AddHours(-5)

gives you dt of Year 1, Day 2, Hour 1, Minute 5, Second 1, millisceond 123

You can also create the datetie/timespans the other way round

KSPDateTime dt2 = new KSPDateTime(3,3);

Gives you year 3, day 3 and the UT will match - it reads the game settings to know if you are in 6hour or 24 hour days

Lastly you can also use Earth Time for RSS, and the usual datetime string formats


KSPDateStructure.SetEarthCalendar();
KSPDateTime dt3 = new KSPDateTime(301.123);
Debug.WriteLine(dt3.ToString("yyyy-MM-dd HH:mm:ss")

This will output 1951-01-01 00:05:01 - as RSS Start date is 1 jan 1951

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...