首頁 php教程 PHP源码 java產生html萬年曆

java產生html萬年曆

Nov 11, 2016 am 10:52 AM

package Str;  
   
import java.util.Calendar;  
/** 
 *  
 *  
 * @project Tool 
 * @type Test8 
 * @Description  
 * @author xuyw 
 * @email xyw10000@163.com 
 * @date 2014-8-9 下午01:45:02 
 * @version 1.0 
 * 
 */ 
public class Test8 {  
   
    /** 
     * @param args 
     */ 
    public static void main(String[] args) {  
        Calendar calendar = Calendar.getInstance();  
        calendar.add(Calendar.MONTH, 0);  
        calendar.set(Calendar.DAY_OF_MONTH, 1);// 设置为1号,当前日期既为本月第一天  
        int firstDay = calendar.get(Calendar.DAY_OF_WEEK) - 1;  
        int monthDays = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);// 当月最后一天  
   
        StringBuilder sbd = new StringBuilder();  
        sbd.append("<table cellspacing=&#39;0&#39; style=&#39;background: url(./img/body.png);&#39;>");  
        sbd.append("<thead><tr>");  
        sbd  
                .append("<th>星期天</th><th>星期一</th><th>星期二</th><th>星期三</th><th>星期四</th><th>星期五</th><th>星期六</th>");  
        sbd.append("</tr></thead>");  
        sbd.append("<tbody><tr>");  
        // 第一行  
        int weekend = 0;// 每周的最后一天的日期  
        for (int i = 0; i < 7; i++) {  
            if (i < firstDay) {  
                sbd.append("<td></td>");  
            } else {  
                sbd.append("<td>" + (i - firstDay + 1) + "</td>");  
            }  
            weekend = i - firstDay + 1;  
        }  
        sbd.append("</tr>");  
        while (weekend < monthDays) {  
            sbd.append("<tr>");  
   
            for (int i = 0; i < 7; i++) {  
                if (weekend + i < monthDays)// 数字小于等于当前月的最后一天  
                {  
                    sbd.append("<td>" + (i + weekend + 1) + "</td>");  
                } else {  
                    sbd.append("<td></td>");  
                }  
   
            }  
            sbd.append("</tr>");  
            weekend += 7;// 周末再加7天  
        }  
   
        sbd.append("<tbody></table>");  
        System.out.println(sbd.toString());  
    }  
}
登入後複製

先前測試就用控制台產生html標籤   將產生的html標籤在頁面展示即可 效果圖如下

java產生html萬年曆

css

* { 
    /* old-style reset here :) */ 
    border: 0px; 
    padding: 0px; 
} 
body { 
    font-family: Helvetica; 
    background: white; 
    text-align: center; 
    /* background: url(../img/body.png) repeat-x; */} 
body h1 { 
    padding-top: 20px; 
    font-size: 36px; 
    color: #335; 
} 
p{font-size:26px;} 
table { 
    border-collapse: separate; 
    border: 1px solid #9DABCE; 
    border-width: 1px 1px 1px 1px; 
    margin: 10px auto; 
    font-size: 30px; 
} 
   
   
td, th { 
    width: 81px; 
    height: 81px; 
    text-align: center; 
    vertical-align: middle; 
    /*background: url(../img/cells.png);*/ 
    color: #444; 
    position: relative; 
} 
th { 
    height: 30px; 
    font-weight: bold; 
    font-size: 14px; 
} 
   
td.sign_in { 
    background-position: 81px 0px; 
    color: red; 
} 
   
td.sign_no{ 
    background: url(../img/cells.png); 
}
登入後複製


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

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

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)