SOL9 2.0 Class: LocalDateTime

 SOL9 C++ Class Library  SOL9 Samples  SOL9 Tutorial  SOL9 FAQ  SOL9 ClassTree 

Source code

/*
 * LocalDateTime.h 
 * Copyright (c) 2011 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// SOL9 2009/08/29
// 2009/12/21 Modified
#pragma once

#include <sol\Object.h>
#include <sol/String.h>
#include <sol/StringT.h>
#include <sol/StringConverter.h>


namespace SOL {

class LocalDateTime :public Object {

public:
    LocalDateTime()
    {
    }

public:
    /**
       */
    void nowToSeconds(__out String& dateTime) {
        char buff[128];
        memset(buff, 0, sizeof(buff));
        nowToSeconds(buff, sizeof(buff));
        dateTime = buff;
    }

public:
    /**
       */
    void nowToSeconds(__out StringT<char>& dateTime) {
        char buff[128];
        memset(buff, 0, sizeof(buff));
        nowToSeconds(buff, sizeof(buff));
        dateTime = buff;
    }

public:
    /**
       */
    //2009/12/21
    const wchar_t* nowToSeconds(__out StringT<wchar_t>& dateTime) {
        char buff[128];
        memset(buff, 0, sizeof(buff));
        nowToSeconds(buff, sizeof(buff));
        StringConverter converter;
        wchar_t* wbuffer =converter.toWideChar(buff);

        dateTime = wbuffer;
        delete [] wbuffer;
        return (const wchar_t*)dateTime;
    }

public:
    /**
       */
    void nowToSeconds(__inout char* buff, int size) {
        SYSTEMTIME systime;

        GetLocalTime(&systime);
        sprintf(buff,
        "%04d/%02d/%02d %02d:%02d:%02d",
        systime.wYear,
        systime.wMonth,
        systime.wDay,
        systime.wHour,
        systime.wMinute,
        systime.wSecond);
    }        

public:
    /**
       */
    void nowToMilliseconds(__out String& dateTime) {
        char buff[128];
        memset(buff, 0, sizeof(buff));

        nowToMilliseconds(buff, sizeof(buff));
        dateTime = buff;
    }

public:
    /**
       */
    void nowToMilliseconds(__out StringT<char>& dateTime) {
        char buff[128];
        memset(buff, 0, sizeof(buff));

        nowToMilliseconds(buff, sizeof(buff));
        dateTime = buff;        
    }


public:
    /**
       */
    void nowToMilliseconds(char* buff, int size) {
        SYSTEMTIME systime;

        GetLocalTime(&systime);
    
        sprintf(buff,
        "%04d-%02d-%02d %02d:%02d:%02d:%03d",
        systime.wYear,
        systime.wMonth,
        systime.wDay,
        systime.wHour,
        systime.wMinute,
        systime.wSecond,
        systime.wMilliseconds);

    }        

};


}



Last modified: 1 Feb 2012

Copyright (c) 2009-2012 Antillia.com ALL RIGHTS RESERVED.