javascript 날짜 상용 방법

2162 단어 자바 script날짜.
1:날짜 와 관련 된 환산 비교:
 
<html>
<head>
<title></title>
<script language="javascript">
function returnMaxDate(){
var datevalue1 = document.getElementById("date1").value;
var datevalue2 = document.getElementById("date2").value;
if(datevalue1 > datevalue2){
return datevalue1;
}else{
return datevalue2;
}
}
</script>
</head>
<body>
<input type="text" name="date1" id="date1">
<input type="text" name="date2" id="date2">
</body>
</html>
2:날짜 의 형식 판단
 
//yyyy-MM-dd
if (!/^\d{4}\-\d\d?\-\d\d?/.test(datavalue1)) {
alert("datevalue1 ")
}
3: ( )
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class TestDate {
public static String getWeekFromDate(String sDate,int type){
if("".equals(sDate)){
return "";
}
SimpleDateFormat df = null;
if(type==0){
df = new SimpleDateFormat("yyyy-MM-dd");
}else if(type==1){
df = new SimpleDateFormat("yyyyMMdd");
}
Date date = null;
try{
date = df.parse(sDate);
}catch(ParseException e){
e.printStackTrace();
}
Calendar cd = Calendar.getInstance();
cd.setTime(date);
int mydate = cd.get(Calendar.DAY_OF_WEEK);
String showDate = "";
switch (mydate) { //mydate 1---7: , , 。。。
case 1:
showDate = " ";
break;
case 2:
showDate = " ";
break;
case 3:
showDate = " ";
break;
case 4:
showDate = " ";
break;
case 5:
showDate = " ";
break;
case 6:
showDate = " ";
break;
default:
showDate = " ";
break;
}
return showDate;
}
}

좋은 웹페이지 즐겨찾기