Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,所以它是on-topic,用于堆栈溢出。
                        
                        5年前关闭。
                                                                                            
                
        
因此,有两个日期,我必须检查date1是否比date2更远。最好的方法是什么?

int date1_day = 21, date1_month = 1, date1_year = 1990;
int date2_day = 19, date2_month = 5, date2_year = 1989;

if(???)
{
   // date1 is further away
}


我正在为这个工作奋斗了几个小时。

最佳答案

在不使用任何逻辑运算符的情况下尝试以下操作:

int date1 =  date1_day + date1_month*100 + date1_year*10000;
int date2 =  date2_day + date2_month*100 + date2_year*10000;

if(date1 > date2)
     printf("date1 is further away than date2\n");

关于c++ - 如何比较程序中的两个日期? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24316715/

10-10 21:38