码农网2022-04-24
select convert(varchar,((datepart(year,getdate())*100+datepart(month,getdate()))*100+datepart(day,getdate()))*100+datepart(hh,getdate()))+convert(varchar,(datepart(minute,getdate())))
1、使用Calendar类/**
* 获取当前日期是星期几<br>
*
* @param dt
* @return 当前日期是星期几
*/
public static String getWeekOfDate(Date dt) {
String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"}
Calendar cal = Calendar.getInstance()
cal.setTime(dt)
int w = cal.get(Calendar.DAY_OF_WEEK) - 1
if (w <0)
w = 0
return weekDays[w]
}
2、使用SimpleDateFormat格式化日期
Date date=new Date()
SimpleDateFormat dateFm = new SimpleDateFormat("EEEE")
dateFm.format(date)
注:格式化字符串存在区分大小写
对于创建SimpleDateFormat传入的参数:EEEE代表星期,如“星期四”;MMMM代表中文月份,如“十一月”;MM代表月份,如“11”;
yyyy代表年份,如“2010”;dd代表天,如“25”
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)