Compare | programming before using PHP to write a simple class, the main function is to solve, a large number of pages need to display a Drop-down list box to select the year/month/day/week. I hope you can learn PHP and Java to help.
The implementation of PHP is as follows:
getCurrentDate.class.php
<?php
/*
* Function: Generate Drop-down list (year/month/day/weekly basis current value)
* Programmer: Xiangli
* Date: 2003-01-19
*/
Class getcurrentdate{
var $Years = 2002;
var $Months = 12;
var $Days = 31;
var $Weeks = 52;
/* Get the Year drop-down list * *
function Getcurrentyear ()
{
for ($i = Date (' Y '); $i >= $this->years; $i--)
{
echo "<option value= ' $i ' >{$i} years </option>\n";
}
}
/* Get the month drop-down list * *
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} month </option>\n";
Else
echo "<option value= ' $m ' >{$m} month </option>\n";
}
}
/* Get the day drop-down list * *
function Getcurrentday ()
{
for ($i = 1; $i <= $this->days; $i + +) {
if ($i = = Date (' d '))
echo "<option value= ' $i ' selected>{$i} day </option>\n";
Else
echo "<option value= ' $i ' >{$i} day </option>\n";
}
}
/* Get week's dropdown list * *
function Getcurrentweek ()
{
for ($i = 1; $i <= $this->weeks; $i + +) {
if ($i = = Date (' W ')
echo "<option value= ' $i ' selected>{$i} week </option>\n";
Else
echo "<option value= ' $i ' >{$i} week </option>\n";
}
}
}
?>
The call is as follows:
Includ (".. /public/getcurrentdate.class.php ");
$getCurrentDate = Net getcurrentdate ();
<select name = "XXXXX" >
<?= $getCurrentDate->getcurrentyear ()?>
</select>
//////////////////////////////////////////////////////////
How to implement Java:
Getcurrentdate.java
/*
* Function: Generate Drop-down list (year/month/day/weekly basis current value)
* Programmer: Xiangli
* Date: 2003-01-19
*/
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");
/* Get the Year drop-down list * *
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 + "year </option>\n";
}
return Content;
}
/* Get the month drop-down list * *
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 + "month </option>\n";
Else
Content + = "<option value= '" + M + "' >" + M + "month </option>\n";
}
return Content;
}
/* Get the day drop-down list * *
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 + "Day </option>\n";
Else
Content + + "<option value= '" + M + "' >" + M + "Day </option>\n";
}
return Content;
}
/* Get week's dropdown list * *
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 + "Week </option>\n";
Else
Content + = "<option value= '" + M + "' >" + M + "Zhou </option>\n";
}
return Content;
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.