SQL Server 和Java中判断上午下午

SQL Server:

select case when (datepart(hour,GETDATE())>=0 and datepart(hour,GETDATE())<12) 
       then 1 else 0 end  as 上午, 
case when (datepart(hour,getdate())>12  and datepart(hour,getdate())<23) 
      then 1 else 0 end as 下午

Java

try {    
GregorianCalendar ca = new GregorianCalendar();    
ca.setTime(new SimpleDateFormat("yy-MM-dd HH:mm:ss").parse("2016-07-28 11:04:36"));    
YYRQDM = ca.get(GregorianCalendar.AM_PM) + 1;
} catch (ParseException e) {   
 e.printStackTrace();
}
    原文作者:ettingshausen
    原文地址: https://www.jianshu.com/p/0907f5862385
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞