一个简单编程思想在php与java中的实现比较:日期类!
Jun 21, 2016 am 09:11 AM比较|编程
以前用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;
}
}
调用方法:

Article chaud

Outils chauds Tags

Article chaud

Tags d'article chaud

Bloc-notes++7.3.1
Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise
Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1
Puissant environnement de développement intégré PHP

Dreamweaver CS6
Outils de développement Web visuel

SublimeText3 version Mac
Logiciel d'édition de code au niveau de Dieu (SublimeText3)

Sujets chauds

Solution : Votre organisation vous demande de modifier votre code PIN

Comment ajuster les paramètres de bordure de fenêtre sous Windows 11 : modifier la couleur et la taille

Comment changer la couleur de la barre de titre sous Windows 11 ?

Comment activer ou désactiver les aperçus miniatures de la barre des tâches sur Windows 11

Problèmes d'erreur OOBELANGUAGE dans la réparation de Windows 11/10

Afficher le guide de mise à l'échelle sur Windows 11

10 façons de régler la luminosité sous Windows 11

Comment désactiver l'authentification de navigation privée pour iPhone dans Safari ?
