六月婷婷综合激情-六月婷婷综合-六月婷婷在线观看-六月婷婷在线-亚洲黄色在线网站-亚洲黄色在线观看网站

明輝手游網中心:是一個免費提供流行視頻軟件教程、在線學習分享的學習平臺!

一個容易編程思想在java與php的相同完成比較!

[摘要]以前用PHP時寫了一個簡單的class,功能主要是解決,大量頁面上需要顯示下拉列表框選擇年/月/日/周之類的。希望對大家學習PHP和java能有幫助。php的實現如下:getCurrentDate....
以前用PHP時寫了一個簡單的class,功能主要是解決,大量頁面上需要顯示下拉列表框選擇年/月/日/周之類的。希望對大家學習PHP和java能有幫助。

php的實現如下:
getCurrentDate.class.php
<?php
/*
* 功能:生成下拉列表(年/月/日/周為當前值)
* 程序員:xiangli
* 日期:2003-01-19
*/

#---------------------------------------------------#
# 修改:2003-03-18#
# 修改原因:添加了周的生成#
#-------------------------------------------------#

class getCurrentDate{
var$Years = 2002;
var$Months = 12;
var$Days = 31;
var$Weeks = 52;

/*獲得年的下拉列表*/
function getCurrentYear()
{
for ($i = Date('Y'); $i >= $this->Years; $i--)
{
echo "<option value='$i'>{$i}年</option>\n";
}
}

/*獲得月的下拉列表*/
function getCurrentMonth()
{
for ($i = 1; $i <= $this->Months; $i++)
{
($i<10)?($m="0".$i):($m=$i);
if($i == date('m'))
echo "<option value='$m' selected>{$m}月</option>\n";
else
echo "<option value='$m'>{$m}月</option>\n";
}
}

/*獲得日的下拉列表*/
function getCurrentDay()
{
for ($i = 1; $i <= $this->Days; $i++){
if($i == date('d'))
echo "<option value='$i' selected>{$i}日</option>\n";
else
echo "<option value='$i'>{$i}日</option>\n";
}
}

/*獲得周的下拉列表*/
function getCurrentWeek()
{
for ($i = 1; $i <= $this->Weeks; $i++){
if($i == date('W'))
echo "<option value='$i' selected>{$i}周</option>\n";
else
echo "<option value='$i'>{$i}周</option>\n";
}
}
}
?>

調用如下:
includ("../public/getCurrentDate.class.php");
$getCurrentDate = net getCurrentDate();
<select name ="xxxxx">
<?=$getCurrentDate->getCurrentYear()?>
</select>
//////////////////////////////////////////////////////////


java的實現方法:
getCurrentDate.java
/*
* 功能:生成下拉列表(年/月/日/周為當前值)
* 程序員:xiangli
* 日期:2003-01-19
*/

// #---------------------------------------------------#
// # 修改:2003-03-18 #
// # 修改原因:添加了周的生成 #
// #-------------------------------------------------#

import java.io.*;
import java.util.*;
import java.text.*;

public class getCurrentDate {
public int Years = 2002;
public int Months = 12;
public int Days = 31;
public int Weeks = 52;
Date myDate = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd w");

/*獲得年的下拉列表*/
public String getCurrentYear()
{
String Content = "";
for (int i =Integer.parseInt(formatter.format(myDate).toString().substring(0, 4)); i >= Years; i--)
{
Content += "<option value='" + i + "'>" + i + "年</option>\n";
 
}
return Content;
}

/*獲得月的下拉列表*/
public String getCurrentMonth()
{
String m;
String Content = "";

for (int i = 1; i <= Months; i++)
{
m=i<10?("0" + i):Integer.toString(i);
if(i == Integer.parseInt(formatter.format(myDate).toString().substring(5, 7)))
Content += "<option value='" + m + "' selected>" + m + "月</option>\n";
else
Content += "<option value='" + m + "'>" + m + "月</option>\n";
}
return Content;
}

/*獲得日的下拉列表*/
public String getCurrentDay()
{
String Content = "";
String m;

for (int i = 1; i <= Days; i++){
m=i<10?("0" + i):Integer.toString(i);
if(i == Integer.parseInt(formatter.format(myDate).toString().substring(8, 10)))
Content += "<option value='" + m + "' selected>" + m + "日</option>\n";
else
Content += "<option value='" + m + "'>" + m + "日</option>\n";
}
return Content;
}

/*獲得周的下拉列表*/
public String getCurrentWeek()
{
String Content = "";
String m;

for (int i = 1; i <= Weeks; i++){
m=i<10?("0" + i):Integer.toString(i);
if(i == Integer.parseInt(formatter.format(myDate).toString().substring(11)))
Content += "<option value='" + m + "' selected>" + m + "周</option>\n";
else
Content += "<option value='" + m + "'>" + m + "周</option>\n";
}
return Content;
}
}


調用方法:
<jsp:useBean id="getCurrentDate" scope="session" class="getCurrentDate" />
<select name="Years">
<%=getCurrentDate.getCurrentYear()%>
</select>
<select name="Months">
<%=getCurrentDate.getCurrentMonth()%>
</select>
<select name="Days">
<%=getCurrentDate.getCurrentDay()%>
</select>
<select name="Weeks">
<%=getCurrentDate.getCurrentWeek()%>
</select>


主站蜘蛛池模板: 中文字幕国产 | 日本乱中文字幕系列在线观看 | 日本一区二区视频免费播放 | 午夜综合网 | 午夜在线观看免费高清在线播放 | 色综合视频 | 日本欧美激情 | 五月天色网址 | 欧美线在线精品观看视频 | 日韩免费高清 | 青草社区在线观看 | 天堂资源中文官网 | 色在线视频播放 | 日韩黄在线观看免费视频 | 在线看日韩 | 亚洲福利影院 | 日韩欧美高清视频 | 日韩欧美高清在线 | 亚洲 欧美 精品 | 亚洲永久视频 | 日噜噜| 在线看福利片 | 亚洲欧美日韩国产精品一区 | 日韩中文字幕在线有码视频网 | 五月综合激情网 | 午夜精品国产 | 天天视频色版 | 日本免费一二三区 | 亚洲精品在线视频观看 | 五月婷综合网 | 孕妇三片高清在线观看 | 日韩永久在线观看免费视频 | 欧美一级性视频 | 热99精品视频 | 日本高清视频www | 五月天婷婷网址 | 亚洲aⅴ | 日本黄色片网址 | 欧美一级做一a做片性视频 欧美一级做性受 | 日韩午夜激情视频 | 日本不卡视频在线视频观看 |