您好,欢迎访问一九零五行业门户网

一个简单编程思想在php与java中的实现比较:日期类!

比较|编程
以前用php时写了一个简单的class,功能主要是解决,大量页面上需要显示下拉列表框选择年/月/日/周之类的。希望对大家学习php和java能有帮助。
php的实现如下:
getcurrentdate.class.php
= $this->years; $i--)
        {
            echo {$i}年\n;
        }
    }
/*获得月的下拉列表*/
    function getcurrentmonth()
    {
        for ($i = 1; $i months; $i++)
        {
            ($i            if($i == date('m'))
                echo {$m}月\n;
            else
                echo {$m}月\n;
        }
    }
/*获得日的下拉列表*/
    function getcurrentday()
    {
        for ($i = 1; $i days; $i++){
            if($i == date('d'))
                echo {$i}日\n;
            else
                echo {$i}日\n;
        }
    }
/*获得周的下拉列表*/
    function getcurrentweek()
    {
        for ($i = 1; $i weeks; $i++){
            if($i == date('w'))
                echo {$i}周\n;
            else
                echo {$i}周\n;
        }
    }    
}
?>
调用如下:
includ(../public/getcurrentdate.class.php);
$getcurrentdate = net getcurrentdate();
=$getcurrentdate->getcurrentyear()?>
//////////////////////////////////////////////////////////
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 += + i + 年\n;
}
        return content;
    }
/*获得月的下拉列表*/
    public string getcurrentmonth()
    {
        string m;
        string content = ;
for (int i = 1; i         {
            m=i            if(i == integer.parseint(formatter.format(mydate).tostring().substring(5, 7)))
                content += + m + 月\n;
            else
                content += + m + 月\n;
        }
        return content;
    }
/*获得日的下拉列表*/
    public string getcurrentday()
    {
        string content = ;
        string m;
for (int i = 1; i             m=i            if(i == integer.parseint(formatter.format(mydate).tostring().substring(8, 10)))
                content += + m + 日\n;
            else
                content += + m + 日\n;
        }
        return content;
    }
/*获得周的下拉列表*/
    public string getcurrentweek()
    {
        string content = ;
        string m;
for (int i = 1; i             m=i            if(i == integer.parseint(formatter.format(mydate).tostring().substring(11)))
                content += + m + 周\n;
            else
                content += + m + 周\n;
        }
        return content;
    }    
}
调用方法:
其它类似信息

推荐信息