我有个JS的要么?
你可以把他改下我是没时间帮你该哈!!!
!--日期框选择-->>
var DS_x,DS_y;
function dateSelector() //构造dateSelector对象,用来实现一个日历形式的日期输入框。
{
var myDate=new Date();
thisyear=myDategetFullYear(); //定义year属性,年份,默认值为当前系统年份。
thismonth=myDategetMonth()+1; //定义month属性,月份,默认值为当前系统月份。
thisdate=myDategetDate(); //定义date属性,日,默认值为当前系统的日。
thisinputName=''; //定义inputName属性,即输入框的name,默认值为空。注意:在同一页中出现多个日期输入框,不能有重复的name!
thisdisplay=display; //定义display方法,用来显示日期输入框。
}
function display() //定义dateSelector的display方法,它将实现一个日历形式的日期选择框。
{
var week=new Array('日','一','二','三','四','五','六');
documentwrite("<style type=text/css>");
documentwrite(" ds_font td,span { font: normal 12px 宋体; color: #000000; }");
documentwrite(" ds_border { border: 1px solid #000000; cursor: hand; background-color: #DDDDDD }");
documentwrite(" ds_border2 { border: 1px solid #000000; cursor: hand; background-color: #DDDDDD }");
documentwrite("</style>");
var M=new String(thismonth);
var d=new String(thisdate);
if(Mlength==1&&dlength==1){
documentwrite("<input style='text-align:center;' id='DS_"+thisinputName+"' name='"+thisinputName+"' value='"+thisyear+"-0"+thismonth+"-0"+thisdate+"' title=双击可进行编缉 ondblclick='thisreadOnly=false;thisfocus()' onblur='thisreadOnly=true' readonly>");}
else if(Mlength==1&&dlength==2){
documentwrite("<input style='text-align:center;' id='DS_"+thisinputName+"' name='"+thisinputName+"' value='"+thisyear+"-0"+thismonth+"-"+thisdate+"' title=双击可进行编缉 ondblclick='thisreadOnly=false;thisfocus()' onblur='thisreadOnly=true' readonly>");}
else if(Mlength==2&&dlength==1){
documentwrite("<input style='text-align:center;' id='DS_"+thisinputName+"' name='"+thisinputName+"' value='"+thisyear+"-"+thismonth+"-0"+thisdate+"' title=双击可进行编缉 ondblclick='thisreadOnly=false;thisfocus()' onblur='thisreadOnly=true' readonly>");}
else if(Mlength==2&&dlength==2){
documentwrite("<input style='text-align:center;' id='DS_"+thisinputName+"' name='"+thisinputName+"' value='"+thisyear+"-"+thismonth+"-"+thisdate+"' title=双击可进行编缉 ondblclick='thisreadOnly=false;thisfocus()' onblur='thisreadOnly=true' readonly>");}
documentwrite("<button style='width:60px;height:18px;font-size:12px;margin:1px;border:1px solid #A4B3C8;background-color:#DFE7EF;' type=button onclick=thisnextSiblingstyledisplay='block' onfocus=thisblur()>日期</button>");
documentwrite("<div style='position:absolute;display:none;text-align:center;width:0px;height:0px;overflow:visible' onselectstart='return false;'>");
documentwrite(" <div style='position:absolute;left:-60px;top:20px;width:142px;height:165px;background-color:#F6F6F6;border:1px solid #245B7D;' class=ds_font>");
documentwrite(" <table cellpadding=0 cellspacing=1 width=140 height=20 bgcolor=#CEDAE7 onmousedown='DS_x=eventx-parentNodestylepixelLeft;DS_y=eventy-parentNodestylepixelTop;setCapture();' onmouseup='releaseCapture();' onmousemove='dsMove(thisparentNode)' style='cursor:move;'>");
documentwrite(" <tr align=center>");
documentwrite(" <td width=12% onmouseover=thisclassName='ds_border' onmouseout=thisclassName='' onclick=subYear(this) title='减小年份'><<</td>");
documentwrite(" <td width=12% onmouseover=thisclassName='ds_border' onmouseout=thisclassName='' onclick=subMonth(this) title='减小月份'><</td>");
documentwrite(" <td width=52%><b>"+thisyear+"</b><b>年</b><b>"+thismonth+"</b><b>月</b></td>");
documentwrite(" <td width=12% onmouseover=thisclassName='ds_border' onmouseout=thisclassName='' onclick=addMonth(this) title='增加月份'>></td>");
documentwrite(" <td width=12% onmouseover=thisclassName='ds_border' onmouseout=thisclassName='' onclick=addYear(this) title='增加年份'>>></td>");
documentwrite(" </tr>");
documentwrite(" </table>");
documentwrite(" <table cellpadding=0 cellspacing=0 width=140 height=20 onmousedown='DS_x=eventx-parentNodestylepixelLeft;DS_y=eventy-parentNodestylepixelTop;setCapture();' onmouseup='releaseCapture();' onmousemove='dsMove(thisparentNode)' style='cursor:move;'>");
documentwrite(" <tr align=center>");
for(i=0;i<7;i++)
documentwrite(" <td>"+week[i]+"</td>");
documentwrite(" </tr>");
documentwrite(" </table>");
documentwrite(" <table cellpadding=0 cellspacing=2 width=140 bgcolor=#EEEEEE>");
for(i=0;i<6;i++)
{
documentwrite(" <tr align=center>");
for(j=0;j<7;j++)
documentwrite(" <td width=10% height=16 onmouseover=if(thisinnerText!=''&&thisclassName!='ds_border2')thisclassName='ds_border' onmouseout=if(thisclassName!='ds_border2')thisclassName='' onclick=getValue(this,documentall('DS_"+thisinputName+"'))></td>");
documentwrite(" </tr>");
}
documentwrite(" </table>");
documentwrite(" <span style=cursor:hand onclick=thisparentNodeparentNodestyledisplay='none'>关闭</span>");
documentwrite(" </div>");
documentwrite("</div>");
dateShow(documentall("DS_"+thisinputName)nextSiblingnextSiblingchildNodes[0]childNodes[2],thisyear,thismonth)
}
function subYear(obj) //减小年份
{
var myObj=objparentNodeparentNodeparentNodecells[2]childNodes;
myObj[0]innerHTML=eval(myObj[0]innerHTML)-1;
dateShow(objparentNodeparentNodeparentNodenextSiblingnextSibling,eval(myObj[0]innerHTML),eval(myObj[2]innerHTML))
}
function addYear(obj) //增加年份
{
var myObj=objparentNodeparentNodeparentNodecells[2]childNodes;
myObj[0]innerHTML=eval(myObj[0]innerHTML)+1;
dateShow(objparentNodeparentNodeparentNodenextSiblingnextSibling,eval(myObj[0]innerHTML),eval(myObj[2]innerHTML))
}
function subMonth(obj) //减小月份
{
var myObj=objparentNodeparentNodeparentNodecells[2]childNodes;
var month=eval(myObj[2]innerHTML)-1;
if(month==0)
{
month=12;
subYear(obj);
}
myObj[2]innerHTML=month;
dateShow(objparentNodeparentNodeparentNodenextSiblingnextSibling,eval(myObj[0]innerHTML),eval(myObj[2]innerHTML))
}
function addMonth(obj) //增加月份
{
var myObj=objparentNodeparentNodeparentNodecells[2]childNodes;
var month=eval(myObj[2]innerHTML)+1;
if(month==13)
{
month=1;
addYear(obj);
}
myObj[2]innerHTML=month;
dateShow(objparentNodeparentNodeparentNodenextSiblingnextSibling,eval(myObj[0]innerHTML),eval(myObj[2]innerHTML))
}
function dateShow(obj,year,month) //显示各月份的日
{
var myDate=new Date(year,month-1,1);
var today=new Date();
var day=myDategetDay();
var selectDate=objparentNodeparentNodepreviousSiblingpreviousSiblingvaluesplit('-');
var length;
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
length=31;
break;
case 4:
case 6:
case 9:
case 11:
length=30;
break;
case 2:
if((year%4==0)&&(year%100!=0)||(year%400==0))
length=29;
else
length=28;
}
for(i=0;i<objcellslength;i++)
{
objcells[i]innerHTML='';
objcells[i]stylecolor='';
objcells[i]className='';
}
for(i=0;i<length;i++)
{
objcells[i+day]innerHTML=(i+1);
if(year==todaygetFullYear()&&(month-1)==todaygetMonth()&&(i+1)==todaygetDate())
objcells[i+day]stylecolor='red';
if(year==eval(selectDate[0])&&month==eval(selectDate[1])&&(i+1)==eval(selectDate[2]))
objcells[i+day]className='ds_border2';
}
}
function getValue(obj,inputObj) //把选择的日期传给输入框
{
var myObj=inputObjnextSiblingnextSiblingchildNodes[0]childNodes[0]cells[2]childNodes;
if(objinnerHTML)
if(objinnerHTMLlength==1&&myObj[2]innerHTMLlength==1)
inputObjvalue=myObj[0]innerHTML+"-0"+myObj[2]innerHTML+"-0"+objinnerHTML;
else if(objinnerHTMLlength==1&&myObj[2]innerHTMLlength==2)
inputObjvalue=myObj[0]innerHTML+"-"+myObj[2]innerHTML+"-0"+objinnerHTML;
else if(objinnerHTMLlength==2&&myObj[2]innerHTMLlength==1)
inputObjvalue=myObj[0]innerHTML+"-0"+myObj[2]innerHTML+"-"+objinnerHTML;
else if(objinnerHTMLlength==2&&myObj[2]innerHTMLlength==2)
inputObjvalue=myObj[0]innerHTML+"-"+myObj[2]innerHTML+"-"+objinnerHTML;
inputObjnextSiblingnextSiblingstyledisplay='none';
for(i=0;i<objparentNodeparentNodeparentNodecellslength;i++)
objparentNodeparentNodeparentNodecells[i]className='';
objclassName='ds_border2'
}
function dsMove(obj) //实现层的拖移
{
if(eventbutton==1)
{
var X=objclientLeft;
var Y=objclientTop;
objstylepixelLeft=X+(eventx-DS_x);
objstylepixelTop=Y+(eventy-DS_y);
}
}
/调用代码
<script language=javascript>
var myDate=new dateSelector();
myDateyear=1900;//morenqiri
myDateinputName='date'; //
myDatedisplay();
</script>
/
java获取一个时间的年月日代码及相关解释说明参考下面代码
package zhidao;
import javautilCalendar;
public class Test {
public static void main(String[] args) {
Calendar cal=CalendargetInstance();//使用日历类
int year=calget(CalendarYEAR);//获取年份
int month=calget(CalendarMONTH)+1;//获取月份,因为从0开始的,所以要加1
int day=calget(CalendarDAY_OF_MONTH);//获取天
Systemoutprintln("结果:"+year+"-"+month+"-"+day);
}
}
万年历代码:
/
@(#)AidyCalenderjava
@author
@version 100 2008/7/19
/
import javaawt;
import javaawtevent;
import javalangStringBuffer;
import javaxswing;
import javautil;
import javaxswingTimer;
import javaxswingborder;
public class AidyCalender extends JFrame implements ActionListener,ItemListener{
Date date = new Date();
private GregorianCalendar gregorianCalendar = new GregorianCalendar();
//定义中英文字符数组存储星期信息,用于转换显示
private String[] stringWeekEn = new String[] { "SUN", "MON", "TUE", "WED",
"THU", "FRI", "SAT" };
private String[] stringWeekCn = new String[] { "星期日", "星期一", "星期二", "星期三",
"星期四", "星期五", "星期六" };
//定义存储月份的信息数组,用于转换显示方示
private String[] stringMonthEn = new String[] { "Jan", "Feb", "Mar", "Apr",
"May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec" };
private String[] stringMonthCn = {"一月","二月","三月","四月","五月","六月",
"七月","八月","九月","十月","十一月","十二月"};
private String[] sysNowTime = new String[6];//sysNowTime 用于存储系统时间的变量
private String[] sysRunTime = new String[6];
private JLabel []labelWeek = new JLabel[7];
private JLabel []labelDay = new JLabel[42];
private JLabel labelTime = new JLabel();
private JPanel panel1 = new JPanel();
private JPanel panel2 = new JPanel();
private JPanel panel3 = new JPanel();
private JComboBox combo1 = new JComboBox();
private JComboBox combo2 = new JComboBox();
private JButton buttonToday = new JButton();
private Border border = BorderFactorycreateRaisedBevelBorder();
private Border border1 = BorderFactorycreateLineBorder(Colorcyan,3);
public AidyCalender(String title) {
super(title);
for (int y = 1900; y < 2101; y++) {
combo1addItem(" " + new Integer(y)toString()+"年");
}
for (int m = 0;m<12;m++){
combo2addItem(" "+stringMonthCn[m]);
}
buttonTodaysetText("今 天");
setLayout(new FlowLayout());
add(panel1);
add(panel2);
add(panel3);
panel1setLayout(new GridLayout(1,3,10,0));
panel1add(combo1);
combo1addItemListener(this);
panel1add(combo2);
combo2addItemListener(this);
panel1add(buttonToday);
buttonTodayaddActionListener(this);
labelTimesetFont(new Font("宋体",FontPLAIN,16));
labelTimesetForeground(ColorMAGENTA);
panel1add(labelTime);
Timer time = new Timer(1000,new TimerListener());
timeaddActionListener(new TimerListener());
//timesetRepeats(true);
timestart();
//labelTimeaddAncestorListener(new TimerListener());
panel2setLayout(new GridLayout(7,7,0,10));
panel2setBackground(Colorwhite);
for(int i=0;i<7;i++){
labelWeek[i] = new JLabel();
labelWeek[i]setHorizontalAlignment(0);
if(i==0||i==6){
labelWeek[i]setBackground(Colorblue);
labelWeek[i]setForeground(ColorRED);
labelWeek[i]setFont(new Font("黑体",FontBOLD,14));
}
else{
labelWeek[i]setForeground(ColorBLACK);
labelWeek[i]setFont(new Font("新宋体",FontPLAIN,14));
}
labelWeek[i]setText(stringWeekCn[i]);
panel2add(labelWeek[i]);
}
for(int i= 0;i<42;i++){
labelDay[i] = new JLabel();
labelDay[i]setHorizontalAlignment(0);
labelDay[i]setText("");
panel2add(labelDay[i]);
}
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
Systemexit(0);
}
});
setSize(300,300);
setBounds(250, 200, 400, 360);
setVisible(true);
setResizable(false);
setDefaultCloseOperation(JFrameEXIT_ON_CLOSE);
getSysDate();
setNowDate();
}
public void actionPerformed(ActionEvent ae){
if(aegetSource()==buttonToday){
setNowDate();
}
}
public void itemStateChanged(ItemEvent aa){
setChangeDate();
}
public int turnWeek(String week){
int i;
for(i=0;i<7;i++)
if(weekequalsIgnoreCase(stringWeekEn[i]))
break;
return i;
}
public int turnMonth(String month){
/
int turnMonth(String month)
@month 系统日期中的月,诸如Jan\Feb
@return int
返回一个整数值,用于寻找stringMonthCn[]数组中对应的中文月份
/
int i;
for(i=0;i<12;i++)
if(monthequalsIgnoreCase(stringMonthEn[i]))
break;
return i;
}
/
setNowDate()
设置当前系统日期
/
public void setNowDate(){
setSysDate(getNowYear(),getNowMonth());
getSysRunDate();
setDateNull();
combo1setSelectedIndex(getShowYear() - 1900);
combo2setSelectedIndex(getShowMonth());
setDays(getMonthDays(getNowYear(),getNowMonth()),getInitWeek(sysRunTime[0]),getNowDay());
//labelTimesetText(sysNowTime[3]);
//labelTimesetHorizontalAlignment(0);
}
/Integer getShowYear()
获取组合框中应该显示的年份
/
public void setSysDate(int year,int month){
gregorianCalendarset(year,month,1);
}
public void setDateNull(){
for(int i=0;i<42;i++){
labelDay[i]setText("");
}
}
public void setChangeDate(){
setSysDate(getComboYear(),getComboMonth());
getSysRunDate();
setDateNull();
setDays(getMonthDays(getComboYear(),getComboMonth()),getInitWeek(sysRunTime[0]),-1);
}
public int getMonthDays(int year, int month) {
/
返回所选年月的天数,因为数组中的数值从0开始,所以3\5\8\10分别代表4\6\9\11几个小月
而1代表2月,经过是否为闰年判断,选择返回28或29天
其余月份为大月,返回31天
/
switch (month) {
case 3:
case 5:
case 8:
case 10:
return 30;//小月返回30天
case 1:
if (gregorianCalendarisLeapYear(year)) {
//isLeapYear(year)确定当前纪元中的指定年份是否为闰年。
return 29;
} else {
return 28;
}//闰年的二月返回29天,平年返回28天
default:
return 31;
//大月返回31天
}
}
/
int getComboYear()
获取组合框中的年份
/
public void getSysDate(){
date = gregorianCalendargetTime();
sysNowTime = (datetoString())split(" ");
}
public void getSysRunDate(){
date = gregorianCalendargetTime();
sysRunTime = (datetoString())split(" ");
}
public int getComboYear(){
return combo1getSelectedIndex()+1900;
}
/
int getComboMonth()
获取月组合框中的整数值,
/
public int getComboMonth(){
return combo2getSelectedIndex();
}
public int getInitWeek(String initWeek){
/
getWeekNow(String initWeek)
@para nowWeek 系统日期中的星期
返回当月中的1号是从星期几开始
/
int nowWeek = 0 ;
for(int i = 0;i<7;i++){
if(initWeekequalsIgnoreCase(stringWeekEn[i])){
nowWeek = i;
break;
}
}
return nowWeek;
}
public int getNowYear(){
return IntegerparseInt(sysNowTime[5]);
}
public int getNowMonth(){
int nowMonth=0;
for(int i=0;i<12;i++){
if(sysNowTime[1]equalsIgnoreCase(stringMonthEn[i]));
nowMonth=i;
break;
}
return nowMonth;
}
public int getNowDay(){
return IntegerparseInt(sysNowTime[2]);
}
public Integer getShowYear(){
return IntegerparseInt(sysNowTime[5]);
}
public Integer getShowMonth(){
/
Integer getShowMonth()
获取在组给框中显示的中文格式月份:如七月\八月等
/
return turnMonth(sysNowTime[1]);
}
public void setDays(int monthDays,int initWeek,int day){
/
void setDays(int monthDays,int initWeek,int day)
@para monthDays 本月天数
@para initWeek 初始星期
@para day 今天日
设置月历
/
setDateNull();
for(int i=initWeek;i<initWeek+monthDays+1;i++){
if((i-initWeek+1)==day){
labelDay[i]setBorder(border1);
labelDay[i]setForeground(ColorBLUE);
labelDay[i]setFont(new Font("黑体",FontBOLD,20));
}else if((i%7==0)||(i%7==6))
labelDay[i]setForeground(ColorRED);
else{
labelDay[i]setForeground(ColorBLACK);
}
labelDay[i]setText(StringvalueOf(i-initWeek+1));
}
for(int i=initWeek+monthDays;i<42;i++)
labelDay[i]setText("");
}
class TimerListener implements ActionListener{
//AdapterDemo var=new AdapterDemo("万年历程序--Aidy");
public void actionPerformed(ActionEvent e) {
GregorianCalendar g = new GregorianCalendar();
String clock = new String((ggetTime()toString()split(" "))[3]);
labelTimesetText(clock);
}
}
public static void main(String args[])
{
try{
UIManagersetLookAndFeel(UIManagergetSystemLookAndFeelClassName());
}catch(Exception e){
throw new RuntimeException(e);
}
AidyCalender var=new AidyCalender("万年历程序--Aidy");
}
}
记事本代码这里已经贴不上了。你百度HI我,我给你。
1、使用new Date()获取当前日期,new Date()getTime()获取当前毫秒数
2、计算公式,等于获取的当前日期减去或者加上一天的毫秒数。一天的毫秒数的计算公式:24小时60分钟60秒1000毫秒,也是86400000毫秒。
举例:
Date curDate = new Date();
var preDate = new Date(curDategetTime() - 2460601000); //前一天
var nextDate = new Date(curDategetTime() + 2460601000); //后一天
以下使用后台输出表示。
扩展资料
var myDate = new Date();
myDategetYear(); //获取当前年份(2位)
myDategetFullYear(); //获取完整的年份(4位,1970-)
myDategetMonth(); //获取当前月份(0-11,0代表1月)
myDategetDate(); //获取当前日(1-31)
myDategetDay(); //获取当前星期X(0-6,0代表星期天)
myDategetTime(); //获取当前时间(从197011开始的毫秒数)
myDategetHours(); //获取当前小时数(0-23)
myDategetMinutes(); //获取当前分钟数(0-59)
myDategetSeconds(); //获取当前秒数(0-59)
myDategetMilliseconds(); //获取当前毫秒数(0-999)
myDatetoLocaleDateString(); //获取当前日期
var mytime=myDatetoLocaleTimeString(); //获取当前时间
myDatetoLocaleString( ); //获取日期与时间
DateprototypeisLeapYear 判断闰年
DateprototypeFormat 日期格式化
DateprototypeDateAdd 日期计算
DateprototypeDateDiff 比较日期差
DateprototypetoString 日期转字符串
DateprototypetoArray 日期分割为数组
DateprototypeDatePart 取日期的部分信息
DateprototypeMaxDayOfDate 取日期所在月的最大天数
DateprototypeWeekNumOfYear 判断日期所在年的第几周
StringToDate 字符串转日期型
IsValidDate 验证日期有效性
CheckDateTime 完整日期时间检查
daysBetween 日期天数差
以上就是关于求Java万年历源代码!!!全部的内容,包括:求Java万年历源代码!!!、java 怎么获取一个时间的年月日、java 急等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)