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

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

Jun 21, 2016 am 09:11 AM
lt nbsp option quot

比较|编程

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

php的实现如下:
getCurrentDate.class.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 "\n";
        }
    }

    /*获得月的下拉列表*/
    function getCurrentMonth()
    {
        for ($i = 1; $i Months; $i++)
        {
            ($i            if($i == date('m'))
                echo "\n";
            else
                echo "\n";
        }
    }

    /*获得日的下拉列表*/
    function getCurrentDay()
    {
        for ($i = 1; $i Days; $i++){
            if($i == date('d'))
                echo "\n";
            else
                echo "\n";
        }
    }
    
    /*获得周的下拉列表*/
    function getCurrentWeek()
    {
        for ($i = 1; $i Weeks; $i++){
            if($i == date('W'))
                echo "\n";
            else
                echo "\n";
        }
    }    
}
?>

调用如下:
includ("../public/getCurrentDate.class.php");
$getCurrentDate = net getCurrentDate();

//////////////////////////////////////////////////////////


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 += "\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 += "\n";
            else
                Content += "\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 += "\n";
            else
                Content += "\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 += "\n";
            else
                Content += "\n";
        }
        return Content;
    }    
}


调用方法:




 



本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前 By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前 By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱門文章標籤

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

解決方法:您的組織要求您更改 PIN 碼 解決方法:您的組織要求您更改 PIN 碼 Oct 04, 2023 pm 05:45 PM

解決方法:您的組織要求您更改 PIN 碼

Windows 11 上調整視窗邊框設定的方法:變更顏色和大小 Windows 11 上調整視窗邊框設定的方法:變更顏色和大小 Sep 22, 2023 am 11:37 AM

Windows 11 上調整視窗邊框設定的方法:變更顏色和大小

如何在 Windows 11 上變更標題列顏色? 如何在 Windows 11 上變更標題列顏色? Sep 14, 2023 pm 03:33 PM

如何在 Windows 11 上變更標題列顏色?

OOBELANGUAGE錯誤Windows 11 / 10修復中出現問題的問題 OOBELANGUAGE錯誤Windows 11 / 10修復中出現問題的問題 Jul 16, 2023 pm 03:29 PM

OOBELANGUAGE錯誤Windows 11 / 10修復中出現問題的問題

Windows 11 上啟用或停用工作列縮圖預覽的方法 Windows 11 上啟用或停用工作列縮圖預覽的方法 Sep 15, 2023 pm 03:57 PM

Windows 11 上啟用或停用工作列縮圖預覽的方法

Windows 11 上的顯示縮放比例調整指南 Windows 11 上的顯示縮放比例調整指南 Sep 19, 2023 pm 06:45 PM

Windows 11 上的顯示縮放比例調整指南

10種在 Windows 11 上調整亮度的方法 10種在 Windows 11 上調整亮度的方法 Dec 18, 2023 pm 02:21 PM

10種在 Windows 11 上調整亮度的方法

如何在Safari中關閉iPhone的隱私瀏覽身份驗證? 如何在Safari中關閉iPhone的隱私瀏覽身份驗證? Nov 29, 2023 pm 11:21 PM

如何在Safari中關閉iPhone的隱私瀏覽身份驗證?

See all articles