Stardate


Stardate: 11005.5  

As promised in https://bkarim.wordpress.com/2010/01/13/stardate/, here is a simplified snippet of C# code to compute stardates!  Enjoy!  😀 

Simple Stardate in C#

Simple Stardate in C#

 

PS for those who would rather see the code in plain text:

DateTime utcNow = DateTime.UtcNow;
double century = Math.Floor( utcNow.Year / 100.0 );
double starCentury = century – 19.0; //Hack: In order to keep it consistent with Star Trek
double starYear = utcNow.Year – ( century * 100.00 );
double starDay = ( utcNow.DayOfYear * 24.0 ) + utcNow.Hour;
double totalHoursInYear = ( DateTime.IsLeapYear( utcNow.Year ) ? 366 : 365 ) * 24;
double starDate = ( starCentury * 10000.0 ) + ( starYear * 100 ) + ( starDay * 100.0 / totalHoursInYear );

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s