选择显示字体大小

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


   以前用php时写了一个简单的class,功能主要是解决,大量页面上需要显示下拉列表框选择年/月/日/周之类的。希望对大家学习phpjava能有帮助。

php的实现如下:
getcurrentdate.class.php
<?php
/*
* 功能:生成下拉列表(年/月/日/周为当前值)
* 程序员:xiangli
* 日期:2003-01-19
*/

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

class getcurrentdate{
  var    &#36;years = 2002;
  var    &#36;months = 12;
  var    &#36;days = 31;
  var    &#36;weeks = 52;
  
    /*获得年的下拉列表*/
    function getcurrentyear()
    {
        for (&#36;i = date(&#39;y&#39;); &#36;i >= &#36;this->years; &#36;i--)
        {
            echo &quot;<option value=&#39;&#36;i&#39;>{&#36;i}年</option>\n&quot;;
        }
    }

    /*获得月的下拉列表*/
    function getcurrentmonth()
    {
        for (&#36;i = 1; &#36;i <= &#36;this->months; &#36;i++)
        {
            (&#36;i<10)?(&#36;m=&quot;0&quot;.&#36;i):(&#36;m=&#36;i);            
            if(&#36;i == date(&#39;m&#39;))
                echo &quot;<option value=&#39;&#36;m&#39; selected>{&#36;m}月</option>\n&quot;;
            else
                echo &quot;<option value=&#39;&#36;m&#39;>{&#36;m}月</option>\n&quot;;
        }
    }

    /*获得日的下拉列表*/
    function getcurrentday()
    {
        for (&#36;i = 1; &#36;i <= &#36;this->days; &#36;i++){
            if(&#36;i == date(&#39;d&#39;))
                echo &quot;<option value=&#39;&#36;i&#39; selected>{&#36;i}日</option>\n&quot;;
            else
                echo &quot;<option value=&#39;&#36;i&#39;>{&#36;i}日</option>\n&quot;;
        }
    }
    
    /*获得周的下拉列表*/
    function getcurrentweek()
    {
        for (&#36;i = 1; &#36;i <= &#36;this->weeks; &#36;i++){
            if(&#36;i == date(&#39;w&#39;))
                echo &quot;<option value=&#39;&#36;i&#39; selected>{&#36;i}周</option>\n&quot;;
            else
                echo &quot;<option value=&#39;&#36;i&#39;>{&#36;i}周</option>\n&quot;;
        }
    }    
}
?>

调用如下:
includ(&quot;../public/getcurrentdate.class.php&quot;);
&#36;getcurrentdate =.net getcurrentdate();
<select name =&quot;xxxxx&quot;>
<?=&#36;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(&quot;yyyy-mm-dd w&quot;);
  
    /*获得年的下拉列表*/
    public string getcurrentyear()
    {
        string content = &quot;&quot;;
        for (int i =  integer.parseint(formatter.format(mydate).tostring().substring(0, 4)); i >= years; i--)
        {
            content += &quot;<option value=&#39;&quot; + i + &quot;&#39;>&quot; + i + &quot;年</option>\n&quot;;
             
        }
        return content;
    }

    /*获得月的下拉列表*/
    public string getcurrentmonth()
    {
        string m;
        string content = &quot;&quot;;
        
        for (int i = 1; i <= months; i++)
        {
            m=i<10?(&quot;0&quot; + i):integer.tostring(i);
            if(i == integer.parseint(formatter.format(mydate).tostring().substring(5, 7)))
                content += &quot;<option value=&#39;&quot; + m + &quot;&#39; selected>&quot; + m + &quot;月</option>\n&quot;;
            else
                content += &quot;<option value=&#39;&quot; + m + &quot;&#39;>&quot; + m + &quot;月</option>\n&quot;;
        }
        return content;
    }

    /*获得日的下拉列表*/
    public string getcurrentday()
    {
        string content = &quot;&quot;;
        string m;
        
        for (int i = 1; i <= days; i++){
            m=i<10?(&quot;0&quot; + i):integer.tostring(i);
            if(i == integer.parseint(formatter.format(mydate).tostring().substring(8, 10)))
                content += &quot;<option value=&#39;&quot; + m + &quot;&#39; selected>&quot; + m + &quot;日</option>\n&quot;;
            else
                content += &quot;<option value=&#39;&quot; + m + &quot;&#39;>&quot; + m + &quot;日</option>\n&quot;;
        }
        return content;
    }
    
    /*获得周的下拉列表*/
    public string getcurrentweek()
    {
        string content = &quot;&quot;;
        string m;
        
        for (int i = 1; i <= weeks; i++){
            m=i<10?(&quot;0&quot; + i):integer.tostring(i);
            if(i == integer.parseint(formatter.format(mydate).tostring().substring(11)))
                content += &quot;<option value=&#39;&quot; + m + &quot;&#39; selected>&quot; + m + &quot;周</option>\n&quot;;
            else
                content += &quot;<option value=&#39;&quot; + m + &quot;&#39;>&quot; + m + &quot;周</option>\n&quot;;
        }
        return content;
    }    
}


调用方法:
<jsp:usebean id=&quot;getcurrentdate&quot; scope=&quot;session&quot; class=&quot;getcurrentdate&quot; />
<select name=&quot;years&quot;>
<%=getcurrentdate.getcurrentyear()%>
</select>
<select name=&quot;months&quot;>
<%=getcurrentdate.getcurrentmonth()%>
</select>
<select name=&quot;days&quot;>
<%=getcurrentdate.getcurrentday()%>
</select>
<select name=&quot;weeks&quot;>
<%=getcurrentdate.getcurrentweek()%>
</select> 


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons