取得本星期的开始和结束日期
来源:互联网 发布:知乎每周精选 rss 编辑:程序博客网 时间:2024/05/06 10:31
<script language="javascript">
function padZero(num)
{
return (num < 10)? '0' + num : num ;
}
function chg_date(range,num1,num2){
//alert(num1+'-'+num2);
if(range=='t' || range=='w' || range=='lw' || range=='r'){
PageForm.from_date.value ='<%=getDate.getStringDateShort()%>';
PageForm.to_date.value =PageForm.from_date.value;}
if(range!='t'){
if(PageForm.from_date.value!=PageForm.to_date){
PageForm.from_date.value ='<%=getDate.getStringDateShort()%>';
PageForm.to_date.value =PageForm.from_date.value;
}
var aStartDate = PageForm.from_date.value.split('-');
var newStartDate = new Date(parseInt(aStartDate[0], 10),parseInt(aStartDate[1], 10) - 1,parseInt(aStartDate[2], 10) + num1);
PageForm.from_date.value = newStartDate.getFullYear()+ '-' + padZero(newStartDate.getMonth() + 1)+ '-' + padZero(newStartDate.getDate());
var aEndDate = PageForm.to_date.value.split('-');
var newEndDate = new Date(parseInt(aEndDate[0], 10),parseInt(aEndDate[1], 10) - 1,parseInt(aEndDate[2], 10) + num2);
PageForm.to_date.value = newEndDate.getFullYear()+ '-' + padZero(newEndDate.getMonth() + 1)+ '-' + padZero(newEndDate.getDate());
}
}
</script>
调用:<input type='button' w',-<%=getDate.getWeek(getDate.getStringDateShort())-1 %>,7-<%=getDate.getWeek(getDate.getStringDateShort())-1 %>);" value='本星期'>
当然,你要加入两个表单来接收这两个日期:
<input type="text >
<input type="text >
附对日期的操作类:
package JavaBean.util;
/**
* Title: 处理日前的类
* Description:
* Copyright: Copyright (c) 2006
* Company: gbpc
* @author: prettywolf
* @version 1.01
*/
import java.util.*;
import java.text.*;
public class GetDate {
public String datetime;
public int year;
public int month;
public int day;
public int hour;
public int minute;
public int second;
public GetDate(){}
public void setDatetime(String newvalue){
this.datetime = newvalue;
}
public String getStrYear(){
return this.datetime.substring(0,4);
}
public String getStrMonth(){
return this.datetime.substring(5,7);
}
public String getStrDay(){
return this.datetime.substring(8,10);
}
public String getStrHour(){
return this.datetime.substring(11,13);
}
public String getStrMinute(){
return this.datetime.substring(14,16);
}
public String getStrSecond(){
return this.datetime.substring(17,19);
}
public static Date getNowDate() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString=formatter.format(currentTime);
ParsePosition pos = new ParsePosition(8);
Date currentTime_2 = formatter.parse(dateString, pos);
return currentTime_2;
}
public static Date getNowDateShort() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString=formatter.format(currentTime);
ParsePosition pos = new ParsePosition(8);
Date currentTime_2 = formatter.parse(dateString, pos);
return currentTime_2;
}
public static String getStringDate(){
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(currentTime);
return dateString;
}
public static String getStringDateShort(){
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = formatter.format(currentTime);
return dateString;
}
public static Date strToDate(String strDate){
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ParsePosition pos=new ParsePosition(0);
Date strtodate=formatter.parse(strDate,pos);
return strtodate;
}
public static String dateToStr(java.util.Date dateDate){
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(dateDate);
return dateString;
}
public static Date strToBirthday(String strDate){
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
ParsePosition pos=new ParsePosition(0);
Date strtodate=formatter.parse(strDate,pos);
return strtodate;
}
public static Date getNow(){
Date currentTime = new Date();
return currentTime;
}
public static long getS(String strDate){
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
ParsePosition pos=new ParsePosition(0);
Date strtodate=formatter.parse(strDate,pos);
return strtodate.getTime();
}
public static String getLastDate(long day) {
Date date=new Date();
long date_3_hm=date.getTime()-3600000*24*day;
Date date_3_hm_date=new Date(date_3_hm);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = formatter.format(date_3_hm_date);
return dateString;
}
public static int getNowDay(String StrDate) {
Date Time1=strToDate(StrDate);
Date Time2=new Date();
long day=Time1.getTime()-Time2.getTime();
return (int)day/(24*60*60*1000);
}
public static int getNowDay(Date StrDate) {
Date Time1=StrDate;
Date Time2=new Date();
long day=Time1.getTime()-Time2.getTime();
return (int)day/(24*60*60*1000);
}
public int getWeek(String date){
Calendar cal = Calendar.getInstance();
int year = Integer.parseInt(date.substring(0,4));
int month = Integer.parseInt(date.substring(5,7));
int day = Integer.parseInt(date.substring(8,10));
cal.set(year,month-1,day);
//String[] dayarray={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
return cal.get(Calendar.DAY_OF_WEEK)-1;
}
}
function padZero(num)
{
return (num < 10)? '0' + num : num ;
}
function chg_date(range,num1,num2){
//alert(num1+'-'+num2);
if(range=='t' || range=='w' || range=='lw' || range=='r'){
PageForm.from_date.value ='<%=getDate.getStringDateShort()%>';
PageForm.to_date.value =PageForm.from_date.value;}
if(range!='t'){
if(PageForm.from_date.value!=PageForm.to_date){
PageForm.from_date.value ='<%=getDate.getStringDateShort()%>';
PageForm.to_date.value =PageForm.from_date.value;
}
var aStartDate = PageForm.from_date.value.split('-');
var newStartDate = new Date(parseInt(aStartDate[0], 10),parseInt(aStartDate[1], 10) - 1,parseInt(aStartDate[2], 10) + num1);
PageForm.from_date.value = newStartDate.getFullYear()+ '-' + padZero(newStartDate.getMonth() + 1)+ '-' + padZero(newStartDate.getDate());
var aEndDate = PageForm.to_date.value.split('-');
var newEndDate = new Date(parseInt(aEndDate[0], 10),parseInt(aEndDate[1], 10) - 1,parseInt(aEndDate[2], 10) + num2);
PageForm.to_date.value = newEndDate.getFullYear()+ '-' + padZero(newEndDate.getMonth() + 1)+ '-' + padZero(newEndDate.getDate());
}
}
</script>
调用:<input type='button' w',-<%=getDate.getWeek(getDate.getStringDateShort())-1 %>,7-<%=getDate.getWeek(getDate.getStringDateShort())-1 %>);" value='本星期'>
当然,你要加入两个表单来接收这两个日期:
<input type="text >
<input type="text >
附对日期的操作类:
package JavaBean.util;
/**
* Title: 处理日前的类
* Description:
* Copyright: Copyright (c) 2006
* Company: gbpc
* @author: prettywolf
* @version 1.01
*/
import java.util.*;
import java.text.*;
public class GetDate {
public String datetime;
public int year;
public int month;
public int day;
public int hour;
public int minute;
public int second;
public GetDate(){}
public void setDatetime(String newvalue){
this.datetime = newvalue;
}
public String getStrYear(){
return this.datetime.substring(0,4);
}
public String getStrMonth(){
return this.datetime.substring(5,7);
}
public String getStrDay(){
return this.datetime.substring(8,10);
}
public String getStrHour(){
return this.datetime.substring(11,13);
}
public String getStrMinute(){
return this.datetime.substring(14,16);
}
public String getStrSecond(){
return this.datetime.substring(17,19);
}
public static Date getNowDate() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString=formatter.format(currentTime);
ParsePosition pos = new ParsePosition(8);
Date currentTime_2 = formatter.parse(dateString, pos);
return currentTime_2;
}
public static Date getNowDateShort() {
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString=formatter.format(currentTime);
ParsePosition pos = new ParsePosition(8);
Date currentTime_2 = formatter.parse(dateString, pos);
return currentTime_2;
}
public static String getStringDate(){
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(currentTime);
return dateString;
}
public static String getStringDateShort(){
Date currentTime = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = formatter.format(currentTime);
return dateString;
}
public static Date strToDate(String strDate){
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
ParsePosition pos=new ParsePosition(0);
Date strtodate=formatter.parse(strDate,pos);
return strtodate;
}
public static String dateToStr(java.util.Date dateDate){
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = formatter.format(dateDate);
return dateString;
}
public static Date strToBirthday(String strDate){
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
ParsePosition pos=new ParsePosition(0);
Date strtodate=formatter.parse(strDate,pos);
return strtodate;
}
public static Date getNow(){
Date currentTime = new Date();
return currentTime;
}
public static long getS(String strDate){
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
ParsePosition pos=new ParsePosition(0);
Date strtodate=formatter.parse(strDate,pos);
return strtodate.getTime();
}
public static String getLastDate(long day) {
Date date=new Date();
long date_3_hm=date.getTime()-3600000*24*day;
Date date_3_hm_date=new Date(date_3_hm);
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String dateString = formatter.format(date_3_hm_date);
return dateString;
}
public static int getNowDay(String StrDate) {
Date Time1=strToDate(StrDate);
Date Time2=new Date();
long day=Time1.getTime()-Time2.getTime();
return (int)day/(24*60*60*1000);
}
public static int getNowDay(Date StrDate) {
Date Time1=StrDate;
Date Time2=new Date();
long day=Time1.getTime()-Time2.getTime();
return (int)day/(24*60*60*1000);
}
public int getWeek(String date){
Calendar cal = Calendar.getInstance();
int year = Integer.parseInt(date.substring(0,4));
int month = Integer.parseInt(date.substring(5,7));
int day = Integer.parseInt(date.substring(8,10));
cal.set(year,month-1,day);
//String[] dayarray={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
return cal.get(Calendar.DAY_OF_WEEK)-1;
}
}
- 取得本星期的开始和结束日期
- 取得周内日期的开始和结束时间
- shell 取得上个月的开始结束日期
- 取得给定日期所在周的开始日期和结束日期
- 功能:取得给定日期所在周的开始日期和结束日期
- 开始日期到结束日期的天数和每天是星期几
- 取得日期的星期
- PHP获取当前日期所在星期(月份)的开始日期与结束日期(实现代码)
- 获取某星期的开始时间和结束时间
- 根据开始和结束时间,计算出该时间段每个星期的开始和结束时间
- 带有开始日期和结束日期的日期选择器
- php取得几天星期几以及这个星期的星期一和下周一对应的日期
- PHP获得指定日期的 星期的开始时间 结束时间
- 当前日期得到本周的开始和结束日期
- 当前日期得到本周的开始和结束日期
- 当前日期得到本周的开始和结束日期
- php获取本周的开始日期和结束日期
- golang获取上月的开始日期和结束日期
- 在Delphi程序中操作注册表
- 多边形自相交判断issimple
- [ubuntu]安装vmware时找不到c header files的小问题
- mysql双机热备份
- JavaScript对象与数组参考大全
- 取得本星期的开始和结束日期
- WEB全能服务器总结,及各种问题处理方法.apache+tomcat+jsp+php+mysql+虚拟主机
- 我的.emacs配置 支持jde speedbar等
- httpd.conf中对php支持的配置
- mini webserver on linux with c
- getting CVS Emacs 23
- 一个验证的问题
- 进军海外,你开始了吗?
- linux下自动启动tomcat