javascript日付によく使われる方法
3020 ワード
1:日付の換算比較によく関わる:
<br/><script language="javascript">
<br>function returnMaxDate(){
<br>var datevalue1 = document.getElementById("date1").value;
<br>var datevalue2 = document.getElementById("date2").value;
<br>if(datevalue1 > datevalue2){
<br>return datevalue1;
<br>}else{
<br>return datevalue2;
<br>}
<br>}
<br></script>
<br/>
<br/>
<br/><input type="text" name="date1" id="date1"/>
<br/><input type="text" name="date2" id="date2"/>
<br/>
<br/>
<br/>
</code></pre>
<br/>2:
<br/>
<pre><code>
<br/>//yyyy-MM-dd
<br/>if (!/^\d{4}\-\d\d?\-\d\d?/.test(datavalue1)) {
<br/>alert("datevalue1 ")
<br/>}
<br/>3: ( )
<br/>import java.text.ParseException;
<br/>import java.text.SimpleDateFormat;
<br/>import java.util.Calendar;
<br/>import java.util.Date;
<br/>public class TestDate {
<br/>public static String getWeekFromDate(String sDate,int type){
<br/>if("".equals(sDate)){
<br/>return "";
<br/>}
<br/>SimpleDateFormat df = null;
<br/>if(type==0){
<br/>df = new SimpleDateFormat("yyyy-MM-dd");
<br/>}else if(type==1){
<br/>df = new SimpleDateFormat("yyyyMMdd");
<br/>}
<br/>Date date = null;
<br/>try{
<br/>date = df.parse(sDate);
<br/>}catch(ParseException e){
<br/>e.printStackTrace();
<br/>}
<br/>Calendar cd = Calendar.getInstance();
<br/>cd.setTime(date);
<br/>int mydate = cd.get(Calendar.DAY_OF_WEEK);
<br/>String showDate = "";
<br/>switch (mydate) { //mydate 1---7: , , 。。。
<br/>case 1:
<br/>showDate = " ";
<br/>break;
<br/>case 2:
<br/>showDate = " ";
<br/>break;
<br/>case 3:
<br/>showDate = " ";
<br/>break;
<br/>case 4:
<br/>showDate = " ";
<br/>break;
<br/>case 5:
<br/>showDate = " ";
<br/>break;
<br/>case 6:
<br/>showDate = " ";
<br/>break;
<br/>default:
<br/>showDate = " ";
<br/>break;
<br/>}
<br/>return showDate;
<br/>}
<br/>}
<br/>
</code></pre>
<div class="clearfix">
<span id="art_bot" class="jbTestPos"/>
</div>
</div>
</div>
</div>