关 键 词:
实现 比较 日期 简单 编程 思想 一个 Content value option
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> 欢迎进入PHP开发资源论坛讨论。
相关文章
图文推荐
论 坛 资 源
·Zope的优点及和Apache+PHP+MySQL的比较
·PHP面向对象、类经典教程[2]
·PHP面向对象、类经典教程[1]
·用 Xdebug 修正 PHP 应用程序中的错误(5)
·用 Xdebug 修正 PHP 应用程序中的错误(4)
·用 Xdebug 修正 PHP 应用程序中的错误(3)
·用 Xdebug 修正 PHP 应用程序中的错误(2)
·用 Xdebug 修正 PHP 应用程序中的错误(1)
·黑防黑:黑客口述—关于Php后门的隐藏技巧
·PRADO框架TDataGrid使用教程(1)
·PHP面向对象、类经典教程[2]
·PHP面向对象、类经典教程[1]
·用 Xdebug 修正 PHP 应用程序中的错误(5)
·用 Xdebug 修正 PHP 应用程序中的错误(4)
·用 Xdebug 修正 PHP 应用程序中的错误(3)
·用 Xdebug 修正 PHP 应用程序中的错误(2)
·用 Xdebug 修正 PHP 应用程序中的错误(1)
·黑防黑:黑客口述—关于Php后门的隐藏技巧
·PRADO框架TDataGrid使用教程(1)
热门技术文档
·Zope的优点及和Apache+PHP+MySQL的比较
·Windows 下的 PHP 扩展编程
·PHP面向对象、类经典教程[2]
·PHP面向对象、类经典教程[1]
·用 Xdebug 修正 PHP 应用程序中的错误(5)
·用 Xdebug 修正 PHP 应用程序中的错误(4)
·用 Xdebug 修正 PHP 应用程序中的错误(3)
·用 Xdebug 修正 PHP 应用程序中的错误(2)
·用 Xdebug 修正 PHP 应用程序中的错误(1)
·php时间求法(二)
·Windows 下的 PHP 扩展编程
·PHP面向对象、类经典教程[2]
·PHP面向对象、类经典教程[1]
·用 Xdebug 修正 PHP 应用程序中的错误(5)
·用 Xdebug 修正 PHP 应用程序中的错误(4)
·用 Xdebug 修正 PHP 应用程序中的错误(3)
·用 Xdebug 修正 PHP 应用程序中的错误(2)
·用 Xdebug 修正 PHP 应用程序中的错误(1)
·php时间求法(二)
最新图文档
本站编辑推荐:(本站开通Delphi4PHP专区,欢迎进入论坛交流!)
- · 3分钟快速了解 Delphi for PHP 特色 (中文), PDF档
- · 购买Delphi for PHP的五大理由, PDF档
- · Delphi for PHP 使用规格介绍, PDF档
- · Delphi for PHP 問答集 (From CodeGear)
- · Delphi for PHP 产品价格表
编缉最近更新文章
网站赞助商
搜索您感兴趣的内容




