2014年9月18日 星期四
取得當月最後一天
JAVA:
public static void main(String[] args) {
SimpleDateFormat sdf = new SimpleDateFormat("dd");
Calendar calendar = Calendar.getInstance();
System.out.println("today="+sdf.format(calendar.getTime()));
calendar.add(Calendar.MONTH,1); //Calendar.MONTH 加上1個月(用add Method)
System.out.println("nextMonthDay="+sdf.format(calendar.getTime()));
//第一天
System.out.println("nextMonthFrist="+sdf.format(getFirstMonthDay(calendar)));
//最後一天
System.out.println("nextMonthLast="+sdf.format(getLastMonthDay(calendar)));
}
//每個月的第一天日期
public static Date getFirstMonthDay(Calendar calendar) {
calendar.set(Calendar.DATE, calendar.getActualMinimum(Calendar.DATE));
return calendar.getTime();
}
//每個月的最後一天日期
public static Date getLastMonthDay(Calendar calendar) {
calendar.set(Calendar.DATE, calendar.getActualMaximum(Calendar.DATE));
return calendar.getTime();
}
Javascript:
Date.prototype.Format = function (fmt) {
var o = {
"M+": this.getMonth() + 1,
"d+": this.getDate(),
"h+": this.getHours(),
"m+": this.getMinutes(),
"s+": this.getSeconds(),
"q+": Math.floor((this.getMonth() + 3) / 3),
"S": this.getMilliseconds()
};
if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
for (var k in o)
if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
return fmt;
}
function showWeekFirstDay()
{
var Nowdate=new Date();
var WeekFirstDay=new Date(Nowdate-(Nowdate.getDay()-1)*86400000);
alert(WeekFirstDay.Format("yyyy-MM-dd"))
}
function showWeekLastDay()
{
var Nowdate=new Date();
var WeekFirstDay=new Date(Nowdate-(Nowdate.getDay()-1)*86400000);
var WeekLastDay=new Date((WeekFirstDay/1000+6*86400)*1000);
alert(WeekLastDay.Format("yyyy-MM-dd"))
}
function showMonthFirstDay()
{
var Nowdate=new Date();
var MonthFirstDay=new Date(Nowdate.getYear(),Nowdate.getMonth(),1);
alert(MonthFirstDay.Format("yyyy-MM-dd"))
}
function showMonthLastDay()
{
var Nowdate=new Date();
var MonthNextFirstDay=new Date(Nowdate.getYear(),Nowdate.getMonth()+1,1);
var MonthLastDay=new Date(MonthNextFirstDay-86400000);
alert(MonthLastDay.Format("yyyy-MM-dd"))
}
Oracle sql:
select extract(day from last_day(sysdate)) from dual;
SELECT a.HSN_CD,
a.ITEM_CD,
A.Item_Nm,
DECODE(a.ITEM_VAL,'*', to_char(extract(day from last_day(sysdate))) , A.Item_Val) ITEM_VAL,
A.Item_Cntnt ,
NVL(B.Hsn_Nm, '共通') Hsn_Nm
FROM TABLENAMEA a
LEFT JOIN TABLENAMEB b
On A.Hsn_Cd = B.Hsn_Cd
Where A.Hsn_Cd = 'A';
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言