动态时间代码,如何用java写一个显示动态时间的程序in a HTML page with a colorful

1,如何用java写一个显示动态时间的程序in a HTML page with a colorful搜一下:如何用java写一个显示动态时间的程序in a HTML page with a colorful background
2,可以在手机上动态时钟代码吗1.可以实时动态显示当前时间与当前日期2.代码结构简洁、清晰、明了知识的汇总:1.HTML52.CSS33.JavaScript重难点汇总:1.各个指针的旋转角度的获?。?首先要明确以下概念:一周为360度、12小时、60分钟、60秒;公式:一周的度数/一周的时间;即得出时针每过一小时要旋转30度;分针每过一分钟要旋转6度;秒针每过一秒钟要旋转6度;下面是代码部分:HTML:<div id="box"><div id="h"></div><div id="min"></div><div id="s"><div class="cen"></div></div><div id="data"></div></div>CSS3:bodybackground-color: #aaa;margin: 0px; padding: 0px;}#boxwidth: 400px;height: 400px;border-radius: 100%;background: url(img/4706.jpg_wh860.jpg)0px 0px no-repeat;background-size: 400px;position: absolute;left: 500px;top: 200px;}#hwidth: 100px;height: 10px;background-color: red;position: relative;top: 195px;left: 200px;}#minwidth: 140px;height: 10px;background-color: yellow;position: relative;top: 185px;left: 200px;}#swidth: 180px;height: 10px;background-color: blue;position: relative;top: 175px;left: 200px;}.cenwidth: 10px;height: 10px;background-color: white;border-radius: 100%;}#dataposition: relative;top: 100px;left: 150px;color: red;font-size: 20px;}JavaScript:function tim()var d = new Date(),//获取当前系统时间year = d.getFullYear(),//得到当前年份mon = d.getMonth(),//得到当前月份date = d.getDate(), //得到当前日期hours = d.getHours(), //得到当前小时minutes = d.getMinutes(), //得到当前分钟seconds = d.getSeconds();//得到当前秒var hou = "";if(hours>12)hou = "下午";}elsehou = "上午";}document.getElementById("data").innerHTML= year+"年"+mon+"月"+date+"日"+"<br />"+hou;var n = document.getElementById("s");//获取秒针IDn.style.transform = "rotate("+(seconds*6-90)+"deg)";//通过当前秒数,得到秒针旋转度数n.style.transformOrigin = "left";//设置秒针旋转的基点var i = document.getElementById("min");//获取分针IDi.style.transform = "rotate("+(minutes*6-90)+"deg)"//通过当前分钟数,得到分针旋转度数i.style.transformOrigin = "left";//设置分针旋转的基点var h = document.getElementById("h");//获取时针IDh.style.transform = "rotate("+((hours*30)+(minutes*0.5)-90)+"deg)"//通过当前小时数 , 得到时针旋转度数h.style.transformOrigin = "left";//设置时针旋转的基点}setInterval("tim()",1000);
3 , 如何修改下列代码使时间可以动态显示用java是很难做到的 , 时间动态显示要实时刷新页面,即使用一个线程单独控制也必须用js来完成<html xmlns=" http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> <script language="javascript"> var t = null; t = setTimeout(time,1000); function time() 用JS写【动态时间代码,如何用java写一个显示动态时间的程序in a HTML page with a colorful】
4,js如何实现动态倒计时效果 js实现动态倒计时效果的步骤:首先是获取到用户输入的目标时间,在获取当前时间,用目标时间减去当前时间,获得时间差;然后,将得到的时间差传化为天数、小时、分钟、秒钟;最后,动态的输出这些剩余时间 。下面我们就来一步一步的实现动态倒计时:1、建立显示的样式html代码:<form>目的日期:<br><br> <input type="text" id="year"><span>年</span> <input type="text" id="month"><span>月</span> <input type="text" id="day"><span>日</span><br><br> <input type="text" id="hour"><span>时</span> <input type="text" id="minute"><span>分</span> <input type="text" id="second"><span>秒</span><br><br> <input type="button" value="http://www.lisdn.com/mnsj/hhwd/确定" onclick="show()"></form><br><br><div class="time1">还剩时间:<br><br> <span id="_d"></span>天<span id="_h"></span>时 <span id="_m"></span>分 <span id="_s"></span>秒</div>css代码:input.time1 span2、实现动态倒计时--js代码第一步:首先是要获取到目标时间,当我们在页面输入目标日期,点击确认后 , 得到目标时间 。function show() //获取目的日期 var myyear=document.getElementById("year").value; var mymonth=document.getElementById("month").value-1; var myday=document.getElementById("day").value; var myhour=document.getElementById("hour").value; var myminute=document.getElementById("minute").value; var mysecond=document.getElementById("second").value; var time=Number(new Date(myyear,mymonth,myday,myhour,myminute,mysecond));}第二步:获取当前时间、然后用目标时间减去当前时间 , 得到剩余时间,即时间差 。//获取当前时间 var nowTime=Date.now();//获取时间差var timediff=Math.round((time-nowTime)/1000);第三步:将得到的时间差传化为天数、时、分、秒//获取还剩多少天var day=parseInt(timediff/3600/24);//获取还剩多少小时var hour=parseInt(timediff/3600%24);//获取还剩多少分钟var minute=parseInt(timediff/60%60);//获取还剩多少秒var second=timediff%60;第四步:输出剩余时间//输出还剩多少时间document.getElementById("_d").innerHTML=day;document.getElementById("_h").innerHTML=hour;document.getElementById("_m").innerHTML=minute;document.getElementById("_s").innerHTML=second;效果图:此时还不是动态的输出 , 还需要我们手动的不断刷新,在输入目标日期 。第五步:使用定时器setTimeout(),动态输出时间setTimeout(show,1000);if(timediff==0) var set=setTimeout(show,1000);if(timediff==0)动态效果图:说明:setInterval() :定义一个间隔性触发计时器,会按照指定的周期(以毫秒计)来调用函数或计算表达式 。该方法会不停地调用函数 , 直到 调用clearInterval()方法来停止setInterval()计时器或窗口被关闭 。总结:5,Java中如何实现显示动态的时间利用死循环和线程,让线程在循环中每sleep1秒,重新获取下系统时间不就是动态显示时间了吗while(true)Date date=new Date(System.currentTimeMillis());SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-ddHH:mm:ss");System.out.println(date);//每一秒刷新下时间tryThread.sleep(1000);//sleep是以ms为单位} catch (InterruptedException e)// TODO Auto-generated catch blocke.printStackTrace();}}你可以试下代码,看看是不是你要的效果用timeout(function(){//这个是显示时间的方法 , Date要重新new的},1000)间隔时间一秒6,谁能为我提供一个动态时间程序<script language="javascript">function showClock() var now = new Date(); var year= now.getFullYear(); var month= now.getMonth(); var date= now.getDate(); var day= now.getDay(); var hours= now.getHours(); var minutes = now.getMinutes(); var seconds = now.getSeconds(); var clck = (hours>=12)?"下午":"上午"; if(hours<=4) clck="夜深了,注意身体,该休息了,白天再忙吧!"; }else if(hours<12) clck="<font color=#ff3300>上午好,又是美好的一天!</font>"; }else if(hours<18) clck="<font color=#ff3300>下午好!外面天气好吗?记得朵朵白云捎来朋友殷殷的祝福 。</font>"; }else if(hours<22) clck="<font color=#ff3300>吃过晚饭了吧!上网放松一下一天的工作 。</font>"; }else clck="<font color=#ff3300>这么晚了,洗洗睡吧!但愿不会影响您明天的工作!</font>"; } hours = (hours<10)?"0"+hours:hours; minutes = (minutes<10)?"0"+minutes:minutes; seconds = (seconds<10)?"0"+seconds:seconds; switch(day) case 0: day="星期日"; break; case 1: day="星期一"; break; case 2: day="星期二"; break; case 3: day="星期三"; break; case 4: day="星期四"; break; case 5: day="星期五"; break; case 6: day="星期六"; break; } var time = year+"年"+(month+1)+"月"+date+"日"+" "+hours + ":" + minutes + ":" + seconds+ " "+day+" "+clck; myclock.innerHTML = time; setTimeout("showClock()",1000);}</script>---------------------------------------调用方法:<body onl oad="showClock()"><div id="myclock"></div>7 , 用JAVA的线程做一个动态时间的代码public class a extends RunnableThread t;public a()t=new Thread(this);JLabel co=new JLable();}public void run()for (; ; )co.setText(new Date().toString());}}}主函数没写,楼主应该回copy吧,实现了那个run方法zd就OK了上面写的代码为什么不用线程休眠嘛!e79fa5e98193e59b9ee7ad9431333234333266给你一个复杂的!自己去研究一下吧---------------------------------------------------------/** MyClock.java*/import java.util.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.applet.*;import java.text.*;/*** a clock* @author IceWorlD*/public class MyClock extends Applet implements Runnableprivate volatile Thread timer; private int lastxs, lastys, lastxm, lastym, lastxh, lastyh; private SimpleDateFormat formatter; private String lastdate; private Font clockFaceFont; private Date currentDate; private Color handColor; private Color numberColor; private int xcenter = 80, ycenter = 55; public void init()int x, y;lastxs = lastys = lastxm = lastym = lastxh = lastyh = 0;formatter = new SimpleDateFormat("EEE MMM dd hh: mm: ss yyyy", Locale.getDefault());currentDate = new Date();lastdate = formatter.format(currentDate);clockFaceFont = new Font("Serif", Font.PLAIN, 14);handColor = Color.BLUE;numberColor = Color.darkGray;trysetBackground(new Color(Integer.parseInt(getParameter("bgcolor"), 16)));}catch(NullPointerException e)catch(NumberFormatException e)trynumberColor = new Color(Integer.parseInt(getParameter("fgcolor1"), 16));}catch(NullPointerException e)catch(NumberFormatException e)trynumberColor = new Color(Integer.parseInt(getParameter("fgcolor1"), 16));}catch(NullPointerException e)catch(NumberFormatException e)resize(300, 300); }/** 绘制显示的主题部分*/public void update(Graphics g)int xh, yh, xm, ym, xs, ys;int s=0, m=10, h=10;String today;currentDate = new Date();formatter.applyPattern("s");trys = Integer.parseInt(formatter.format(currentDate));}catch(NumberFormatException n)s = 0;}formatter.applyPattern("m");trym = Integer.parseInt(formatter.format(currentDate));}catch(NumberFormatException n)m = 10;}formatter.applyPattern("h");tryh = Integer.parseInt(formatter.format(currentDate));}catch(NumberFormatException n)h = 10;}xs = (int)(Math.cos(s*Math.PI/30 - Math.PI/2) * 45 + xcenter);ys = (int)(Math.sin(s*Math.PI/30 - Math.PI/2) * 45 + ycenter);xm = (int)(Math.cos(m*Math.PI/30 - Math.PI/2) * 40 + xcenter);ym = (int)(Math.sin(m*Math.PI/30 - Math.PI/2) * 40 + ycenter);xh = (int)(Math.cos((h*30+m/2)*Math.PI/180 - Math.PI/2) * 30 + xcenter);yh = (int)(Math.sin((h*30+m/2)*Math.PI/180 - Math.PI/2) * 30 + ycenter);formatter.applyPattern("EEE MMM dd HH: mm: ss yyyy");today = formatter.format(currentDate);g.setFont(clockFaceFont);g.setColor(getBackground());if(xs != lastxs || ys != lastys)g.drawLine(xcenter, ycenter, lastxs, lastys);g.drawString(lastdate, 5, 125);}if(xm != lastxm || ym != lastym)g.drawLine(xcenter, ycenter-1, lastxm, lastym);g.drawLine(xcenter-1, ycenter, lastxm, lastym);}if(xh != lastxh || yh != lastyh)g.drawLine(xcenter, ycenter-1, lastxh, lastyh);g.drawLine(xcenter-1, ycenter, lastxh, lastyh);}g.setColor(numberColor);g.drawString(today, 5, 125);g.drawLine(xcenter, ycenter, xs, ys);g.setColor(handColor);g.drawLine(xcenter, ycenter-1, xm, ym);g.drawLine(xcenter-1, ycenter, xm, ym);g.drawLine(xcenter, ycenter-1, xh, yh);g.drawLine(xcenter-1, ycenter, xh, yh);lastxs = xs; lastys = ys;lastxm = xm; lastym = ym;lastxh = xh; lastyh = yh;lastdate = today;currentDate = null;}public void paint(Graphics g)g.setFont(clockFaceFont);g.setColor(handColor);g.drawArc(xcenter-50, ycenter-50, 100, 100, 0, 360);g.setColor(numberColor);g.drawString("9", xcenter-45, ycenter+3);g.drawString("3", xcenter+40, ycenter+3);g.drawString("12", xcenter-5, ycenter-37);g.drawString("6", xcenter-3, ycenter+45);//g.setColor(numberColor);g.drawString(lastdate, 5, 125);g.drawLine(xcenter, ycenter, lastxs, lastys);g.setColor(handColor);g.drawLine(xcenter, ycenter-1, lastxm, lastym);g.drawLine(xcenter-1, ycenter, lastxm, lastym);g.drawLine(xcenter, ycenter-1, lastxh, lastyh);g.drawLine(xcenter-1, ycenter, lastxh, lastyh);}//public void start()timer = new Thread(this);timer.start();}public void stop()timer = null;}//public void run()Thread me = Thread.currentThread();while(timer == me)tryThread.currentThread().sleep(100);}catch(InterruptedException e)repaint();}}/* class ClockWindowEvent extends WindowAdapterpublic void windowClosing(WindowEvent e)System.exit(0);}ClockWindowEvent()public void actionPerformed(ActionEvent e) // TODO Auto-generated method stub}}*/public static void main(String args[])Frame f = new Frame("知道是干什么的了吧~");f.setSize(200, 180);MyClock mc = new MyClock();mc.init();mc.start();f.add(mc);f.show(); }}-------------------------------------------------------import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.util.*;public class frametestpublic static void main(string[] args)jframe f = new myframe();f.setdefaultcloseoperation(jframe.exit_on_close);f.setvisible(true); }}class myframe extends jframeprivate jlabel label = new jlabel(); private thread th; public myframe()this.init();this.add(label);th = new thread()public void run()while(true)date d = new date();string s = string.format("%tt", d);label.settext(s);trythread.sleep(1000);} catch(exception e)}}}};th.start(); } private void init()this.setsize(300, 200);this.setlocation(300, 200);this.setlayout(new flowlayout()); }}

    推荐阅读