时钟代码

更新时间:2023-03-01 10:26:41 阅读: 评论:0

要个简单一点的小时钟代码~

这个是文字时钟代码:
<script>

var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")

function getthedate(){
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var hours=mydate.getHours()
var minutes=mydate.getMinutes()
var conds=mydate.getSeconds()
var dn="AM"
if (hours>=12)
dn="PM"
if (hours>12){
hours=hours-12
}
if (hours==0)
hours=12
if (minutes<=9)
minutes="0"+minutes
if (conds<=9)
conds="0"+conds
//change font size here
var cdate="<small><font color='000000' face='Arial'><b>"+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+" "+hours+":"+minutes+":"+conds+" "+dn
+"</b></font></small>"
if (document.all)
document.all.clock.innerHTML=cdate
el
document.write(cdate)
}
if (!document.all)
getthedate()
function goforit(){
if (document.all)
tInterval("getthedate()",1000)
}

</script>
<body onload="goforit()">
<span id="clock"></span>

c语言时钟代码

#include<graphics.h> /* 引入graphic.h */
#include<math.h> /* 引入math.h */
#include<dos.h> /* 引入dos.h */
#define pi 3.1415926 /*定义pi=3.14159*/
#define X(a,b,c) x=a*cos(b*c*pi/180-pi/2)+300;
#define Y(a,b,c) y=a*sin(b*c*pi/180-pi/2)+240;
#define d(a,b,c) X(a,b,c);Y(a,b,c);line(300,240,x,y) /*定义……*/
void init() /*初始化程序*/
{int i,l,x1,x2,y1,y2; /*定义……*/
tbkcolor(1); /*设置颜色*/
circle(300,240,200); /*作园*/
circle(300,240,205);
circle(300,240,5);
for(i=0;i<60;i++) /*循环(算时间)*/
{if(i%5==0) l=15;
el l=5;
x1=200*cos(i*6*pi/180)+300;
y1=200*sin(i*6*pi/180)+240;
x2=(200-l)*cos(i*6*pi/180)+300;
y2=(200-l)*sin(i*6*pi/180)+240;
line(x1,y1,x2,y2);
}
}
main()
{
int x,y;
int gd=VGA,gm=2;
unsigned char h,m,s; /*定义*/
struct time t[1];
initgraph(&gd,&gm,"d:\\tc");
init();
twritemode(1);
gettime(t);
h=t[0].ti_hour;
m=t[0].ti_min;
s=t[0].ti_c; /*定义时分秒*/
tcolor(7); /*设置颜色*/
d(150,h,30);
tcolor(14);
d(170,m,6);
tcolor(4);
d(190,s,6);
while(!kbhit()) /*获取键盘相应*/
{while(t[0].ti_c==s)
gettime(t); /*C语言中得到时间的函数*/
sound(400); /*计算时间……*/
delay(70);
sound(200);
delay(30);
nosound();
tcolor(4);
d(190,s,6);
s=t[0].ti_c;
d(190,s,6);
if (t[0].ti_min!=m)
{
tcolor(14);
d(170,m,6);
m=t[0].ti_min;
d(170,m,6);
}
if (t[0].ti_hour!=h)
{ tcolor(7);
d(150,h,30);
h=t[0].ti_hour;
d(150,h,30);
sound(1000);
delay(240);
nosound();
delay(140);
sound(2000);
delay(240);
nosound();
}
}
getch(); /*设置空格后退出*/
clograph();
}

具体的。。就是套用用几个函数算时间。。
不要对这种很长的东西害怕,其实大部分都是在画这个钟~
加油哦~

FLASH时钟代码

http://www.qqywf.com/show/fd.swf?id=4288(
粉色FLASH可爱时钟
女生专用
MIni款)
http://www.qqywf.com/show/fd.swf?id=3836(
简洁数字FLASH时钟版
黑白电子表)
http://www.qqywf.com/show/fd.swf?id=3826(
玩的就是心跳_视觉FLASH时钟代码
黑色款)
http://www.qqywf.com/show/fd.swf?id=3825(QQ
空间水晶FLASH时钟代码)
http://www.qqywf.com/show/fd.swf?id=3328(QQ
空间黑色FLASH时钟
旋转特效)
http://www.qqywf.com/skin.swf?m=37(
按住可拖动的QQ空间时钟FLASH代码
个性ING)

JAVA画时钟代码

importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
importsun.util.calendar.Gregorian;
importjava.util.Calendar;
importjava.util.GregorianCalendar;

publicclassClockPointerextendsJFrame{
intx,y,x0,y0,r,h,olds_x,olds_y,oldm_x,oldm_y,oldh_x,oldh_y,
ss,mm,hh,old_m,old_h,ang;
finaldoubleRAD=Math.PI/180;

publicClockPointer(){
super("Java时钟");
tDefaultCloOperation(JFrame.EXIT_ON_CLOSE);
Imageimage=getToolkit().getImage("clock.gif");
tIconImage(image);
tSize(400,400);
tBackground(Color.white);
//tLocation(300,150);
this.tLocationRelativeTo(null);
tResizable(true);
intdelay=1000;
//创建一个监听事件

tVisible(true);
ActionListenerdrawClock=newActionListener(){
publicvoidactionPerformed(ActionEventevt){
repaint();
}
};
//创建一个时间计数器,每一秒触发一次
newTimer(delay,drawClock).start();
}

java.text.SimpleDateFormatfmTime=newjava.text.SimpleDateFormat("HH:mm:ss");
//绘制图形
publicvoidpaint(Graphicsg){
super.paint(g);
g.tFont(null);
Graphics2Dg2D=(Graphics2D)g;

Intsints=getInts();
intL=ints.left/2,T=ints.top/2;
h=getSize().height;
g.tColor(Color.white);
//画圆
g2D.tStroke(newBasicStroke(2.0f));
g.tColor(Color.gray);
g.drawOval(L+40,T+40,h-80,h-80);
r=h/2-40;
x0=40+r-5+L;
y0=40+r-5-T;
ang=60;
//绘制时钟上的12个字
for(inti=1;i<=12;i++){
x=(int)((r+10)*Math.cos(RAD*ang)+x0);
y=(int)((r+10)*Math.sin(RAD*ang)+y0);
g.tColor(Color.black);
g.drawString(""+i,x,h-y);
ang-=30;
}
//获得现在的时间
Calendarnow=newGregorianCalendar();
intnowh=now.get(Calendar.HOUR_OF_DAY);
intnowm=now.get(Calendar.MINUTE);
intnows=now.get(Calendar.SECOND);

Stringst=fmTime.format(now.getTime());
//在窗体上显示时间
g.tColor(Color.pink);
g.fillRect(L,T,50,28);
g.tColor(Color.blue);
g.drawString(st,L+2,T+26);

//计算时间与度数的关系
ss=90-nows*6;
mm=90-nowm*6;
hh=90-nowh*30-nowm/2;
x0=r+40+L;
y0=r+40+T;
g2D.tStroke(newBasicStroke(1.2f));
//擦除秒针
//if(olds_x>0){
//g.tColor(getBackground());
////g.tColor(Color.gray);
//g.drawLine(x0,y0,olds_x,h-olds_y);//(?)
//}
//绘制秒针
x=(int)(r*0.9*Math.cos(RAD*ss))+x0;
y=(int)(r*0.9*Math.sin(RAD*ss))+y0-2*T;
g.tColor(Color.yellow);
g.drawLine(x0,y0,x,h-y);
olds_x=x;
olds_y=y;
g2D.tStroke(newBasicStroke(2.2f));
//擦除分针
//if(old_m!=mm){
//g.tColor(getBackground());
//g.drawLine(x0,y0,oldm_x,h-oldm_y);
//}
//绘制分针
x=(int)(r*0.7*Math.cos(RAD*mm))+x0;
y=(int)(r*0.7*Math.sin(RAD*mm))+y0-2*T;
g.tColor(Color.green);
g.drawLine(x0,y0,x,h-y);
oldm_x=x;
oldm_y=y;
old_m=mm;
g2D.tStroke(newBasicStroke(3.2f));
//擦除时针
//if(old_h!=hh){
//g.tColor(getBackground());
//g.drawLine(x0,y0,oldh_x,h-oldh_y);
//}
//绘制时针
x=(int)(r*0.5*Math.cos(RAD*hh))+x0;
y=(int)(r*0.5*Math.sin(RAD*hh))+y0-2*T;
g.tColor(Color.red);
g.drawLine(x0,y0,x,h-y);
oldh_x=x;
oldh_y=y;
old_h=hh;
}

publicstaticvoidmain(String[]args){
newClockPointer();
}
}

//整理一下

vb中怎样做出时钟?

VB可使用Timer控件、Line控件和绘图或加载图片等制作指针式时钟。

Timer 控件,通过引发 Timer 事件,Timer 控件可以有规律地隔一段时间执行一次代码。

Line 控件,Line 控件是图形控件,它显示水平线、垂直线或者对角线。

运行时不能使用 Move 方法移动 Line 控件,但是可以通过改变 X1、X2、Y1 和 Y2
属性来移动它或者调整它的大小。

Circle 方法,在对象上画圆、椭圆或弧。

以下是通过加载图片的指针式时钟代码:

OptionExplicit
PrivateConstPI=3.1415926
DimX(1)AsSingle,Y(1)AsSingle
DimOriAngleAsSingle,DestAngleAsSingle,rAsSingle
PrivateSubRotateLine(objLAsLine,bsPointXAsSingle,bsPointYAsSingle,RotateAngleAsSingle)
WithobjL
X(0)=.X1
Y(0)=.Y1
X(1)=.X2
Y(1)=.Y2
EndWith
DimiAsInteger
Fori=0To1
IfX(i)-bsPointX<>0Then
OriAngle=Atn((Y(i)-bsPointY)/(X(i)-bsPointX))
El
OriAngle=IIf(Y(i)>bsPointY,PI/2,1.5*PI)
EndIf
IfX(i)-bsPointX<0Then
IfOriAngle<0Then
OriAngle=PI-Abs(OriAngle)
El
OriAngle=PI+Abs(OriAngle)
EndIf
EndIf
DestAngle=OriAngle+RotateAngle
r=Sqr((X(i)-bsPointX)^2+(Y(i)-bsPointY)^2)
X(i)=bsPointX+r*Cos(DestAngle)
Y(i)=bsPointY+r*Sin(DestAngle)
Nexti
WithobjL
.X1=X(0)
.Y1=Y(0)
.X2=X(1)
.Y2=Y(1)
EndWith
EndSub
PrivateSubForm_Load()
Timer1.Interval=1000
DimiAsLong
Fori=1ToVal(Mid(Time$,7,2))
RotateLineLine3,Line3.X1,Line3.Y1,1*PI/30
Next
Fori=1ToVal(Mid(Time$,4,2))
RotateLineLine2,Line2.X1,Line2.Y1,1*PI/30
Next
Fori=1ToVal(Mid(Time$,1,2))*5'对时针
RotateLineLine1,Line1.X1,Line1.Y1,1*PI/30
Next
Fori=1ToVal(Mid(Time$,4,2))'对时针
RotateLineLine1,Line1.X1,Line1.Y1,1*PI/360
Next
EndSub
PrivateSubTimer1_Timer()
RotateLineLine3,Line3.X1,Line3.Y1,1*PI/30
RotateLineLine2,Line2.X1,Line2.Y1,PI/1800
IfMid(Time$,7,2)="00"OrMid(Time$,7,2)="30"Then
RotateLineLine1,Line1.X1,Line1.Y1,1*PI/720
EndIf
Me.Caption=Time$
EndSub

vb 时钟代码

Private
Sub
Form_Load()
Form1.AutoRedraw
=
True
Form1.Height
=
3500
Form1.Width
=
3500
Form1.Scale
(-100,
100)-(100,
-100)
'这里VB是以正X和负Y开始原始坐标,就是Y坐标和我们平时画的相反
Line1.X1
=
0:
Line1.Y1
=
0
Line2.X1
=
0:
Line2.Y1
=
0
Line3.X1
=
0:
Line3.Y1
=
0
Line1.BorderColor
=
RGB(0,
0,
0)
Line1.BorderWidth
=
3
Line2.BorderColor
=
RGB(0,
0,
255)
Line2.BorderWidth
=
2
Line3.BorderColor
=
RGB(255,
0,
0)
Shape1.Top
=
95
'这里因为Y坐标是相反的,所以要正数
Shape1.Left
=
-95
Line3.BorderWidth
=
1
Shape1.BorderStyle
=
3
Shape1.BorderWidth
=
3
Shape1.Width
=
190
Shape1.Height
=
190
Shape1.BorderColor
=
RGB(0,
0,
255)
Timer1.Interval
=
1000
End
Sub
Private
Sub
Timer1_Timer()
sx
=
Cos((180
-
6
*
Second(Time))
*
3.14159
/
180)
*
65
'COS。不知道怎么说
sy
=
Sin((180
-
6
*
Second(Time))
*
3.14159
/
180)
*
65
'同上,的秒针反方向转了
Line3.X2
=
sx
Line3.Y2
=
sy
mx
=
Cos((180
-
6
*
Minute(Time))
*
3.14159
/
180)
*
65
my
=
Sin((180
-
6
*
Minute(Time))
*
3.14159
/
180)
*
65
Line2.X2
=
mx
Line2.Y2
=
my
hx
=
Cos((180
-
(30
*
Hour(Time)
+
30
*
Minute(Time)
/
60))
*
3.14159
/
180)
*
40
hy
=
Sin((180
-
(30
*
Hour(Time)
+
30
*
Minute(Time)
/
60))
*
3.14159
/
180)
*
40
Line1.X2
=
hx
Line1.Y2
=
hy
Form1.CurrentX
=
-2
Form1.CurrentY
=
80
Form1.Print
"12"
Form1.CurrentX
=
75
Form1.CurrentY
=
-8
Form1.Print
"3"
Form1.CurrentX
=
-80
Form1.CurrentY
=
-8
Form1.Print
"9"
End
Sub

本文发布于:2023-02-28 19:50:00,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/zhishi/a/167763760172033.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:时钟代码.doc

本文 PDF 下载地址:时钟代码.pdf

下一篇:返回列表
标签:时钟   代码
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 实用文体写作网旗下知识大全大全栏目是一个全百科类宝库! 优秀范文|法律文书|专利查询|