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();
}

你可能感兴趣的:(SQL Server 和Java中判断上午下午)