Poco 를 이용한 날짜 계산

#include "ofApp.h"
#include "Poco\Timespan.h"
#include "Poco\DateTime.h"
using namespace Poco;
//--------------------------------------------------------------
void ofApp::setup(){

    Timespan _fewDays(3, 0, 0, 0, 0); // 3일 
    DateTime _today(2016,1,1);
    DateTime _before = _today - _fewDays;
    DateTime _ago = _today + _fewDays;

    cout << "today is  : " << _today.year() << "/" << _today.month() << "/" << _today.day() << endl;
    cout << "- 3 days  : " << _before.year() << "/" << _before.month() << "/" << _before.day() << endl;
    cout << "+ 3 days  : " << _ago.year() << "/" << _ago.month() << "/" << _ago.day() << endl;

    
    // 오늘로 날짜 리셋
    _today = DateTime(ofGetYear(), ofGetMonth(), ofGetDay()); 
    DateTime _olyrimpicDay(2018, 2, 9);
    Timespan dday = _olyrimpicDay - _today + 1; // 오늘 부터 1일
    cout << dday.days()  << endl; // 평창 올림픽 까지 남은 날.
}



C# 만큼 편리한 계산이 가능함.

Yamecoder 야매코더_
C++(oF) 2016.07.10 21:24

댓글을 달아 주세요

Powerd by Tistory, designed by criuce
rss