#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    1
    Rep Power
    0

    Newbie Help with a Time/date conversion Program


    Hi I am a newbie programmer (no not a student) I have been trying to teach myself for the past year, with only basic luck. Now I really wish to build a C++ program for a Online game my wife plays. I have a PHP script that works off the games server time, but I want to change it to C++ application that I can just type in the stardate in the format of 20130627.0718 and get the game time result in the proper game format of UFP IC Date: 17 June 2404. as well as the RSE time. Below is the php script for it which is tested and works. Any help would be appreciated. THANKS. :)

    ===========================================

    <!-- Begin Star Date -->

    <div id="p-date" class="portal">
    <h5>Current Date</h5>
    <div class="body">
    <ul>
    <li>Stardate <?php echo gmdate("Ymd.Hi", time()-(25200)); ?></li>
    <li><?php
    // Basic variables
    $UFPDaysInYear = 365.24219;
    $RSEDaysInYear = 380;
    $UFPSecInYear = $UFPDaysInYear * 24 * 60 * 60;
    $RSESecInYear = $RSEDaysInYear * 16 * 100 * 55;

    // List of RSE months
    $RSEMonths = array ("1-Fire", "2-Fire", "3-Fire", "4-Fire", "1-Air", "2-Air", "3-Air", "4-Air", "5-Air", "1-Earth", "2-Earth", "3-Earth", "4-Earth", "5-Earth", "1-Water", "2-Water", "3-Water", "4-Water", "5-Water");

    // UFP Date
    // Timestamp: This very moment - Holotime (PST) + DST
    $now = time() - 28800;
    // Timestamp: OOC Start of 3:1 ratio: 2011-05-01
    $startOOC = mktime(0, 0, 0, 1, 1, 2012);
    // Timestamp: IC equivalent: 2392-05-01
    $startIC = mktime(0, 0, 0, 1, 1, 2400);
    // Timestamp: Current new IC date
    $curIC = (($now - $startOOC) * 3) + $startIC;
    // Current new IC date in Human-readable format
    $curICNice = date("F j, Y", $curIC);
    // Output
    echo "UFP: " . $curICNice . "</li>\n";

    // RSE Date
    // Timestamp: Sundering
    $startRSE = strtotime("1 January 0369");
    // Timestamp: UFP years since Sundering
    $UFPSecSinceSund = $curIC - $startRSE;
    // RSE years since Sundering
    $RSECurYear = floor($UFPSecSinceSund / $RSESecInYear);
    // Timestamp: Days in the current RSE year
    $RSECurDaysInSec = $UFPSecSinceSund % $RSESecInYear;
    // Days in the current RSE year
    $RSECurDays = floor($RSECurDaysInSec / (55 * 100 * 16));
    // Current RSE Month
    $RSECurMonth = $RSEMonths[floor($RSECurDays / 20)];
    // Current RSE day
    $RSECurDay = $RSECurDays - (floor($RSECurDays / 20) * 20);
    // Output
    echo "\t\t\t\t\t\t\t\t<li>RSE: " . $RSECurDay . "-" . $RSECurMonth . ", " . $RSECurYear . "</li>";
    ?>
    </ul>
    </div>
    </div>
    <!-- End Star Date -->
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,091
    Rep Power
    2222
    The date/time functions are found in time.h . mktime is there, only it takes as its input a struct tm (from the time.h file):
    Code:
    /*
     * A structure for storing all kinds of useful information about the
     * current (or another) time.
     */
    struct tm
    {
    	int	tm_sec;		/* Seconds: 0-59 (K&R says 0-61?) */
    	int	tm_min;		/* Minutes: 0-59 */
    	int	tm_hour;	/* Hours since midnight: 0-23 */
    	int	tm_mday;	/* Day of the month: 1-31 */
    	int	tm_mon;		/* Months *since* january: 0-11 */
    	int	tm_year;	/* Years since 1900 */
    	int	tm_wday;	/* Days since Sunday (0-6) */
    	int	tm_yday;	/* Days since Jan. 1: 0-365 */
    	int	tm_isdst;	/* +1 Daylight Savings Time, 0 No DST,
    				 * -1 don't know */
    };
    I do not know of anything like strtotime(), but you could assign the values to a struct tm; if it's an input string, then you'd have to parse it yourself before assigning the value to a struct tm.

    To get the current time, you call time(), which returns the number of seconds since the Beginning of Time(UNIX), 0000h 1970 Jan 01. 32-bit definitions for time_t are only good until sometime in early 2038. To convert time in time_t to a struct tm, use either gmtime() or localtime() for UTC and local time respectively (there's a system variable that keeps track of your time zone). mktime is the inverse function that converts a struct tm to a time_t value.

    There are a few functions for displaying date and/or time as a string. strftime() allows you to specify the format, which is what your date() function appears to be doing.

    I'm sure that there are pages and tutorials on-line that explain the time.h functions and provide practical examples.

IMN logo majestic logo threadwatch logo seochat tools logo