本文整理汇总了C++中Date类的典型用法代码示例。如果您正苦于以下问题:C++ Date类的具体用法?C++ Date怎么用?C++ Date使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Date类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
Date operator-(Date a, int b) { Date q; q.Set(a.Get() - b); return q; }
示例2: d
void CheckStatPlan::setNextRunTime (PlanItem &oPlan)
{
Date d (oPlan.m_sNextRunTime);
Date dNow;
char sDate[15];
char sMsg[1024] = {0};
if (oPlan.m_iIntervalType == 1) //时间间隔(秒)
{
int iAddSecs = atoi (oPlan.m_sTimeInterval);
if (iAddSecs <= 0) {
strcpy (sDate, "30000101000000");
}
else {
d.addSec (iAddSecs);
if (oPlan.m_iDataType == 0) {
while (strcmp(d.toString(), dNow.toString()) <= 0)
d.addSec (iAddSecs);
//修正动态刷新指标的数据时间
Date dData (d.toString());
dData.addSec (0 - atoi(oPlan.m_sTimeInterval));
strcpy (oPlan.m_sDataEndTime, dData.toString());
dData.addSec (0 - atoi(oPlan.m_sTimeInterval));
strcpy (oPlan.m_sDataBeginTime, dData.toString());
}
strcpy (sDate, d.toString());
}
}
else if (oPlan.m_iIntervalType == 2) //每个月固定时间
{
strcpy (sDate, oPlan.m_sNextRunTime);
while (strcmp(sDate, dNow.toString()) <= 0)
getNextMonth (sDate, oPlan.m_sTimeInterval);
}
else {
//##异常, 置无穷大
strcpy (sDate, "30000101000000");
strcpy (sMsg, "interval_type 字段值非法, 请检查修改");
}
//update table
DEFINE_QUERY (qry);
if (sMsg[0])
{
qry.setSQL ("update B_Check_Stat_Plan "
" set next_run_time = to_date(:vDate,'yyyymmddhh24miss'),"
" Message = :vMsg "
" where plan_id = :vPlanID "
);
qry.setParameter ("vMsg", sMsg);
}
else {
qry.setSQL ("update B_Check_Stat_Plan "
" set next_run_time = to_date(:vDate,'yyyymmddhh24miss')"
" where plan_id = :vPlanID "
);
}
qry.setParameter ("vPlanID", oPlan.m_iPlanID);
qry.setParameter ("vDate", sDate);
qry.execute();
qry.close();
if (sMsg[0]) {
qry.setSQL ("Insert into b_check_stat_log ( "
" log_id, plan_id, msg_time, message ) "
" values (:vLogID, :vPlanID, sysdate, '[RUN] '||:vMsg )"
);
qry.setParameter ("vLogID", getNextStatLogID());
qry.setParameter ("vPlanID", oPlan.m_iPlanID);
qry.setParameter ("vMsg", sMsg);
qry.execute();
}
qry.commit ();
#ifdef _debug
Log::log (0, "设置下一次运行时间:%s", sDate);
#endif
}
示例3: initFromYearMonthDay
/// copy constructor
Date::Date(const Date& other)
: m_baseYear(other.baseYear()), m_assumedBaseYear(other.assumedBaseYear())
{
initFromYearMonthDay(other.year(), other.monthOfYear(), other.dayOfMonth());
}
示例4:
int operator-(Date a, Date b) { return a.Get() - b.Get(); }
示例5: main
int main()
{
// test Date class
Date d;
d.set_month(1).set_day(2).set_year(3);
cout << "date is initially " << d << endl;
cout << "date is post-incremented " << d++ << endl;
cout << "date is now " << d << endl;
cout << "date is pre-incremented " << ++d << endl;
cout << "date is now " << d << endl;
d = d + 5;
cout << "date is added by 5 " << d << endl;
cout << endl;
// test Name class
Name n("Name", "Test");
cout << "Name is " << n << endl;
cout << endl;
// test Person class
Person p("Person", "Class", 1, 2, 3);
cout << "Person is " << p << endl;
cout << endl;
// test Student derived class
Student s("Student", "Derived", 4, 5, 6, 3.5);
cout << "Student is " << s << endl;
cout << endl;
// test Employee derived class
Employee e("Employee", "Derived", 5, 6, 7, 8, 9, 10);
cout << "Employee is " << e << endl;
cout << endl;
// array of ptr to Person
Person *parray[3] = { &p,&s,&e };
for (int i = 0; i < 3; i++) {
cout << "parray[" << i << "] = " << *parray[i] << endl;
}
cout << endl;
// array of reference to Person
// ERROR: Person &ref_array[3] = { &p,&s,&e };
// array of reference to Person, by embedding reference in a structure
struct {
Person &p;
} ref[3] = { {p}, {s}, {e} };
for (int i = 0; i < 3; i++) {
cout << "ref[" << i << "].p = " << ref[i].p << endl;
}
cout << endl;
// copy constructor, and alternate form of copy constructor
cout << "person count before copy construct= " << Person::get_count() << endl;
Person p2(p);
cout << "p2: " << p2 << endl;
cout << "person count after copy construct= " << Person::get_count() << endl;
cout << endl;
cout << "person count before copy alternate construct= " << Person::get_count() << endl;
Person p3 = p;
cout << "p3: " << p3 << endl;
cout << "person count after alternate copy construct= " << Person::get_count() << endl;
cout << endl;
// object assignment
Person p4;
cout << "default person p4: " << p4 << endl;
p4 = p;
cout << "person p4 after assignment: " << p4 << endl;
p4 = p4;
cout << "person p4 after self assignment: " << p4 << endl;
cout << endl;
// const object
const Person p5("Const", "Person", 9,9,9);
cout << "const person " << p5 << endl;
// ERROR p5 = p;
cout << endl;
// terminating
cout << "program terminating" << endl;
cout << endl;
}
示例6: return
bool Date::operator==(const Date &date) const {
return (this->mod_julian_day() == date.mod_julian_day());
}
示例7: test_conversions
void test_conversions(void)
{
printf("test_conversions - start");
Date d;
printf("test_conversions - date <--> time_t");
// Date <--> time_t
time_t t;
t = time(NULL);
d.SetValue(t);
d.SetCurrent();
t = d;
printf("test_conversions - date <--> struct tm*");
// Date <--> struct tm*
struct tm* stm;
t = time(NULL);
stm = localtime(&t);
d.SetValue(stm);
d.SetCurrent();
const struct tm* cstm = d;
printf("test_conversions - date <--> xmlChar*");
// Date <--> xmlChar*
xmlChar* xmlc = (xmlChar*)xmlMalloc(24);
memcpy(xmlc, "2002/10/30 10:33:00", 19);
d.SetValue(xmlc);
const xmlChar* cxmlc = d;
printf("test_conversions - date <--> char*");
// Date <--> char*
char* c = "2002/10/30 10:33:00";
d.SetValue(c);
const char* cc = d;
#ifdef _WIN32
/*
// Date <--> CTime
CTime ct;
d.SetValue(ct);
ct = (CTime)d;
// Date <--> COleDateTime
COleDateTime codt;
d.SetValue(codt);
codt = (COleDateTime)d;
// Date <--> DATE
DATE D;
d.SetValue(D);
D = d;
*/
#endif _WIN32
printf("test_conversions - done");
}
示例8: main
int main (void)
{
Date ad;
Date bd;
Date cd;
printf("ad is (%s)\n", ad.GetValue()());
printf("ad is also (%s)\n", ad.GetValue("%Y-%m-%d-%H-%M-%S")());
bd.SetValue("07/13/2001 01:02:03.456", "%m/%d/%Y %H:%M:%S");
printf("bd is (%s)\n", bd.GetValue()());
printf("bd is also (%s)\n", bd.GetValue("%m/%d/%Y %H:%M:%S")());
printf("bd is also (%s)\n", bd.GetValue("%Y%m%d%H%M%S")());
printf("bd is also (%s)\n", bd.EDate()());
printf("bd is also (%s)\n", bd.EDate()());
printf("bd is also (%s)\n", bd.EDate()());
printf("bd is also (%s)\n", bd.EDate()());
twine tmp, tmp2;
tmp2 = bd.EDate();
tmp.format("Date: %s\r\n", tmp2() );
printf("%s\n", tmp());
printf("Before direct format\n");
tmp.format("Date: %s\r\n", bd.GetValue("%Y%m%d%H%M%S")() );
printf("After direct format\n");
printf("%s", tmp() );
printf("Before EDate format\n");
tmp.format("Date: %s\r\n", bd.EDate()() );
printf("After EDate format\n");
printf("%s", tmp() );
ad.Floor();
bd = ad;
bd.Ceil();
printf("ad is (%s) bd is (%s)\n", ad.GetValue()(), bd.GetValue()());
cd.SetValue("7/4/2001", "%m/%d/%Y");
printf("cd is (%s)\n", cd.GetValue()());
cd.SetValue("7/4/89", "%m/%d/%Y");
printf("cd is (%s)\n", cd.GetValue()());
cd.SetValue("7/4/01", "%m/%d/%Y");
printf("cd is (%s)\n", cd.GetValue()());
cd.SetValue("20010714080910.123", "%Y%m%d%H%M%S");
printf("cd is (%s)\n", cd.GetValue()());
cd.SetValue("2001/09/01 00:08:05");
printf("Initial cd is (%s)\n", cd.GetValue()());
cd.AddSec(-65);
printf("cd is (%s)\n", cd.GetValue()());
ad.SetValue("2001/08/09 12:00:00");
bd.SetValue("2001/08/09 12:30:00");
if(bd - ad > SLib::Interval(10, MINUTES)){
printf("(%s) - (%s) has a difference greater than 10 minutes\n",
bd.GetValue()(), ad.GetValue()());
}
if(bd - ad > SLib::Interval(20, MINUTES)){
printf("(%s) - (%s) has a difference greater than 20 minutes\n",
bd.GetValue()(), ad.GetValue()());
}
if(bd - ad > SLib::Interval(1, DAY)){
printf("(%s) - (%s) has a difference greater than 1 day\n",
bd.GetValue()(), ad.GetValue()());
}
test_conversions();
return 0;
}
示例9:
bool China::SseImpl::isBusinessDay(const Date& date) const {
Weekday w = date.weekday();
Day d = date.dayOfMonth();
Month m = date.month();
Year y = date.year();
if (isWeekend(w)
// New Year's Day
|| (d == 1 && m == January)
|| (y == 2005 && d == 3 && m == January)
|| (y == 2006 && (d == 2 || d == 3) && m == January)
|| (y == 2007 && d <= 3 && m == January)
|| (y == 2007 && d == 31 && m == December)
|| (y == 2009 && d == 2 && m == January)
|| (y == 2011 && d == 3 && m == January)
|| (y == 2012 && (d == 2 || d == 3) && m == January)
|| (y == 2013 && d <= 3 && m == January)
|| (y == 2014 && d == 1 && m == January)
// Chinese New Year
|| (y == 2004 && d >= 19 && d <= 28 && m == January)
|| (y == 2005 && d >= 7 && d <= 15 && m == February)
|| (y == 2006 && ((d >= 26 && m == January) ||
(d <= 3 && m == February)))
|| (y == 2007 && d >= 17 && d <= 25 && m == February)
|| (y == 2008 && d >= 6 && d <= 12 && m == February)
|| (y == 2009 && d >= 26 && d <= 30 && m == January)
|| (y == 2010 && d >= 15 && d <= 19 && m == January)
|| (y == 2011 && d >= 2 && d <= 8 && m == February)
|| (y == 2012 && d >= 23 && d <= 28 && m == January)
|| (y == 2013 && d >= 11 && d <= 15 && m == February)
|| (y == 2014 && d >= 31 && m == January)
|| (y == 2014 && d <= 6 && m == February)
// Ching Ming Festival
|| (y <= 2008 && d == 4 && m == April)
|| (y == 2009 && d == 6 && m == April)
|| (y == 2010 && d == 5 && m == April)
|| (y == 2011 && d >=3 && d <= 5 && m == April)
|| (y == 2012 && d >= 2 && d <= 4 && m == April)
|| (y == 2013 && d >= 4 && d <= 5 && m == April)
|| (y == 2014 && d == 7 && m == April)
// Labor Day
|| (y <= 2007 && d >= 1 && d <= 7 && m == May)
|| (y == 2008 && d >= 1 && d <= 2 && m == May)
|| (y == 2009 && d == 1 && m == May)
|| (y == 2010 && d == 3 && m == May)
|| (y == 2011 && d == 2 && m == May)
|| (y == 2012 && ((d == 30 && m == April) ||
(d == 1 && m == May)))
|| (y == 2013 && ((d >= 29 && m == April) ||
(d == 1 && m == May)))
|| (y == 2014 && d >= 1 && d <=3 && m == May)
// Tuen Ng Festival
|| (y <= 2008 && d == 9 && m == June)
|| (y == 2009 && (d == 28 || d == 29) && m == May)
|| (y == 2010 && d >= 14 && d <= 16 && m == June)
|| (y == 2011 && d >= 4 && d <= 6 && m == June)
|| (y == 2012 && d >= 22 && d <= 24 && m == June)
|| (y == 2013 && d >= 10 && d <= 12 && m == June)
|| (y == 2014 && d == 2 && m == June)
// Mid-Autumn Festival
|| (y <= 2008 && d == 15 && m == September)
|| (y == 2010 && d >= 22 && d <= 24 && m == September)
|| (y == 2011 && d >= 10 && d <= 12 && m == September)
|| (y == 2012 && d == 30 && m == September)
|| (y == 2013 && d >= 19 && d <= 20 && m == September)
|| (y == 2014 && d == 8 && m == September)
// National Day
|| (y <= 2007 && d >= 1 && d <= 7 && m == October)
|| (y == 2008 && ((d >= 29 && m == September) ||
(d <= 3 && m == October)))
|| (y == 2009 && d >= 1 && d <= 8 && m == October)
|| (y == 2010 && d >= 1 && d <= 7 && m == October)
|| (y == 2011 && d >= 1 && d <= 7 && m == October)
|| (y == 2012 && d >= 1 && d <= 7 && m == October)
|| (y == 2013 && d >= 1 && d <= 7 && m == October)
|| (y == 2014 && d >= 1 && d <= 7 && m == October)
)
return false;
return true;
}
示例10: DaysSinceEpoch
// Get the number of days between the two given dates.
int Date::operator-(const Date &other) const
{
return DaysSinceEpoch() - other.DaysSinceEpoch();
}
示例11: switch
int StatServ::GetFieldValue(int iFieldID,TFieldValue * pTFieldValue)
{
char sTemp[200];
int iValue;
static Date date;
class OrgMgr orgmgr;
//基本域
switch ( iFieldID){
case FA_S_ORG_LEVELID100:
{
if (pServ!=NULL){
int iOrgID=pServ->getOrgID(date.toString());
int iOrgLevelID=-1;
for (;iOrgID>=0;){
iOrgLevelID=orgmgr.getLevel(iOrgID);
if (iOrgLevelID==100)
break;
iOrgID=orgmgr.getParentID(iOrgID);
}
if (iOrgLevelID==100)
pTFieldValue->AutoSetValue(iOrgID);
else
pTFieldValue->SetDefaultValue();
}
else{
pTFieldValue->SetDefaultValue();
}
}
break;
case FA_S_ORG_LEVELID200:
{
if (pServ!=NULL){
int iOrgID=pServ->getOrgID(date.toString());
int iOrgLevelID=-1;
for (;iOrgID>=0;){
iOrgLevelID=orgmgr.getLevel(iOrgID);
if (iOrgLevelID==200)
break;
iOrgID=orgmgr.getParentID(iOrgID);
}
if (iOrgLevelID==200)
pTFieldValue->AutoSetValue(iOrgID);
else
pTFieldValue->SetDefaultValue();
}
else{
pTFieldValue->SetDefaultValue();
}
}
break;
case FA_S_ORG_LEVELID300:
{
if (pServ!=NULL){
int iOrgID=pServ->getOrgID(date.toString());
int iOrgLevelID=-1;
for (;iOrgID>=0;){
iOrgLevelID=orgmgr.getLevel(iOrgID);
if (iOrgLevelID==300)
break;
iOrgID=orgmgr.getParentID(iOrgID);
}
if (iOrgLevelID==300)
pTFieldValue->AutoSetValue(iOrgID);
else
pTFieldValue->SetDefaultValue();
}
else{
pTFieldValue->SetDefaultValue();
}
}
break;
case FA_S_ORG_LEVELID400:
{
if (pServ!=NULL){
int iOrgID=pServ->getOrgID(date.toString());
int iOrgLevelID=-1;
for (;iOrgID>=0;){
iOrgLevelID=orgmgr.getLevel(iOrgID);
if (iOrgLevelID==400)
break;
iOrgID=orgmgr.getParentID(iOrgID);
}
if (iOrgLevelID==400)
pTFieldValue->AutoSetValue(iOrgID);
//.........这里部分代码省略.........
示例12: printDate
void printDate(Date d)
{
cout << d.year() << "-" << d.month() << "-" << d.day() << endl;
}
示例13: handleRecurrence
int CmdTimesheet::execute (std::string& output)
{
int rc = 0;
// Scan the pending tasks.
handleRecurrence ();
std::vector <Task> all = context.tdb2.all_tasks ();
context.tdb2.commit ();
// What day of the week does the user consider the first?
int weekStart = Date::dayOfWeek (context.config.get ("weekstart"));
if (weekStart != 0 && weekStart != 1)
throw std::string (STRING_DATE_BAD_WEEKSTART);
// Determine the date of the first day of the most recent report.
Date today;
Date start;
start -= (((today.dayOfWeek () - weekStart) + 7) % 7) * 86400;
// Roll back to midnight.
start = Date (start.month (), start.day (), start.year ());
Date end = start + (7 * 86400);
// Determine how many reports to run.
int quantity = 1;
std::vector <std::string> words = context.a3.extract_words ();
if (words.size () == 1)
quantity = strtol (words[0].c_str (), NULL, 10);;
std::stringstream out;
for (int week = 0; week < quantity; ++week)
{
Date endString (end);
endString -= 86400;
std::string title = start.toString (context.config.get ("dateformat"))
+ " - "
+ endString.toString (context.config.get ("dateformat"));
Color bold (Color::nocolor, Color::nocolor, false, true, false);
out << "\n"
<< (context.color () ? bold.colorize (title) : title)
<< "\n";
// Render the completed table.
ViewText completed;
completed.width (context.getWidth ());
completed.add (Column::factory ("string", " "));
completed.add (Column::factory ("string", STRING_COLUMN_LABEL_PROJECT));
completed.add (Column::factory ("string.right", STRING_COLUMN_LABEL_DUE));
completed.add (Column::factory ("string", STRING_COLUMN_LABEL_DESC));
std::vector <Task>::iterator task;
for (task = all.begin (); task != all.end (); ++task)
{
// If task completed within range.
if (task->getStatus () == Task::completed)
{
Date compDate (task->get_date ("end"));
if (compDate >= start && compDate < end)
{
Color c;
if (context.color ())
autoColorize (*task, c);
int row = completed.addRow ();
std::string format = context.config.get ("dateformat.report");
if (format == "")
format = context.config.get ("dateformat");
completed.set (row, 1, task->get ("project"), c);
if(task->has ("due"))
{
Date dt (task->get_date ("due"));
completed.set (row, 2, dt.toString (format));
}
std::string description = task->get ("description");
int indent = context.config.getInteger ("indent.annotation");
std::map <std::string, std::string> annotations;
task->getAnnotations (annotations);
std::map <std::string, std::string>::iterator ann;
for (ann = annotations.begin (); ann != annotations.end (); ++ann)
description += "\n"
+ std::string (indent, ' ')
+ Date (ann->first.substr (11)).toString (context.config.get ("dateformat"))
+ " "
+ ann->second;
completed.set (row, 3, description, c);
}
}
}
out << " " << format (STRING_CMD_TIMESHEET_DONE, completed.rows ()) << "\n";
if (completed.rows ())
out << completed.render ()
<< "\n";
//.........这里部分代码省略.........
示例14: DayOfWeek
int DayOfWeek(Date date) {
return (date.Get() + 6) % 7;
}
示例15: filter
int CmdInfo::execute (std::string& output)
{
int rc = 0;
// Apply filter.
std::vector <Task> filtered;
filter (filtered);
if (! filtered.size ())
{
context.footnote (STRING_FEEDBACK_NO_MATCH);
rc = 1;
}
// Get the undo data.
std::vector <std::string> undo;
if (context.config.getBoolean ("journal.info"))
undo = context.tdb2.undo.get_lines ();
// Determine the output date format, which uses a hierarchy of definitions.
// rc.dateformat.info
// rc.dateformat
std::string dateformat = context.config.get ("dateformat.info");
if (dateformat == "")
dateformat = context.config.get ("dateformat");
std::string dateformatanno = context.config.get ("dateformat.annotation");
if (dateformatanno == "")
dateformatanno = dateformat;
// Render each task.
std::stringstream out;
std::vector <Task>::iterator task;
for (task = filtered.begin (); task != filtered.end (); ++task)
{
ViewText view;
view.width (context.getWidth ());
view.add (Column::factory ("string", STRING_COLUMN_LABEL_NAME));
view.add (Column::factory ("string", STRING_COLUMN_LABEL_VALUE));
// If an alternating row color is specified, notify the table.
if (context.color ())
{
Color alternate (context.config.get ("color.alternate"));
view.colorOdd (alternate);
view.intraColorOdd (alternate);
}
Date now;
// id
int row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_ID);
view.set (row, 1, (task->id ? format (task->id) : "-"));
std::string status = ucFirst (Task::statusToText (task->getStatus ()));
// description
Color c;
autoColorize (*task, c);
std::string description = task->get ("description");
int indent = context.config.getInteger ("indent.annotation");
std::map <std::string, std::string> annotations;
task->getAnnotations (annotations);
std::map <std::string, std::string>::iterator ann;
for (ann = annotations.begin (); ann != annotations.end (); ++ann)
description += "\n"
+ std::string (indent, ' ')
+ Date (ann->first.substr (11)).toString (dateformatanno)
+ " "
+ ann->second;
row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_DESC);
view.set (row, 1, description, c);
// status
row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_STATUS);
view.set (row, 1, status);
// project
if (task->has ("project"))
{
row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_PROJECT);
view.set (row, 1, task->get ("project"));
}
// priority
if (task->has ("priority"))
{
row = view.addRow ();
view.set (row, 0, STRING_COLUMN_LABEL_PRIORITY);
view.set (row, 1, task->get ("priority"));
}
// dependencies: blocked
{
//.........这里部分代码省略.........