时钟代码怎么编写(用易语言怎样编时钟)

本文目录
- 用易语言怎样编时钟
- C++\编写一个时钟程序,模拟数字时钟的显示
- 用C++编写图形时钟程序
- 易语言怎么写时钟代码
- 怎么在电脑上设置代码时钟
- 如何使用JS实现一个简易数码时钟
- 时钟程序(C语言)怎么写
- C语言编程问题,做一个控制台时钟代码是怎么写的
- c语言怎么样编写一个时钟程序
- 要个简单一点的小时钟代码~
用易语言怎样编时钟
很简单的,,在窗口放一个 时钟组件和标签组件, 把时钟的时钟周期属性设置为1000。(1000=1秒 以此类推),然后双击时钟组件,在时钟的时钟周期写代码:
标签1.标题 = 到文本 (取年份 (取现行时间 ())) + “-” + 到文本 (取月份 (取现行时间 ())) + “-” + 到文本 (取日 (取现行时间 ())) + “ ” + 到文本 (取小时 (取现行时间 ())) + “:” + 到文本 (取分钟 (取现行时间 ())) + “:” + 到文本 (取秒 (取现行时间 ()))
运行结果是 xxxx-xx-xx xx:xx:xx 格式的时间。
或者写代码:
标签1.标题 = 到文本 (取现行时间 ())
运行结果是:xxxx年XX月XX日XX时XX分XX秒,这种格式的时间
C++\编写一个时钟程序,模拟数字时钟的显示
程序代码如下:
#include《iostream》
#include《windows.h》
using namespace std;
class Clock{
public:
Clock(short h=0,short m=0,short s=0):h(h),m(m),s(s){
}
void displayTime();
private:
short h;
short m;
short s;
};void Clock::displayTime(){
while(true){
cout《《h《《’:’《《m《《’:’《《s《《“ “;
Sleep(1000);
cout《《’\r’;
if(!(s=++s%60))
if(!(m=++m%60))
h=++h%24;
}
} int main()
{
Clock A(23,59,55);
A.displayTime();
return 0;
}
扩展资料:
定义一个日期类,包括年、月、日三个成员变量,显示日期的方法如下:
publicclassDemo{
publicstaticvoidmain(Stringargs){
Datedate1=newDate(1994,5,22);
date1.showInfo();
Datedate2=newDate();
date2.year=1995;
date2.month=6;
date2.day=29;
date2.showInfo();
}
}
//日期类:
publicclassDate{
intyear;
intmonth;
intday;
//构造方法
publicDate(intyear,intmonth,intday){
this.year=year;
this.month=month;
this.day=day;
}
publicDate(){
}
publicvoidshowInfo(){
System.out.println(year+“年“+month+“月“+day+“日“);
}
}
用C++编写图形时钟程序
你好这是我用mfc编写的一个时钟程序我不用你存话费你采纳就ok了别不采纳我可是花了很长时间来弄的源程序//这是关键代码voidCClockView::OnDraw(CDC*pDC){ CClockDoc*pDoc=GetDocument(); ASSERT_VALID(pDoc); //TODO:adddrawcodefornativedatahere CBitmapbg; bg.LoadBitmap(IDB_BITMAP1); CDCdc; dc.CreateCompatibleDC(pDC); dc.SelectObject(bg); pDC-》BitBlt(0,0,400,400,&dc,0,0,SRCCOPY); CTimetm; tm=CTime::GetCurrentTime();//得到系统的时分秒inti=tm.GetMinute()-1;//60 intj=tm.GetHour();//24 intn=tm.GetSecond();//60/* CStringstr; str.Format(“%d:%d“,j,i); MessageBox(str);*/ //2460 floatmin=(float)(i-14)/60*2*3.1415; floathour=(float)(j-3)/12*2*3.1415;//角度 floatsec=(float)(n-14)/60*2*3.1415; //原点位置intorg_x=200; intorg_y=200; //时针 inthour_ar=90;//长度 inth_x=hour_ar*cos(hour)+200; inth_y=hour_ar*sin(hour)+200; //分针 intmin_ar=140;//长度 intm_x=min_ar*cos(min)+200; intm_y=min_ar*sin(min)+200; //秒针 intsec_ar=170;//长度 ints_x=sec_ar*cos(sec)+200; ints_y=sec_ar*sin(sec)+200;CPenp1(PS_SOLID,4,RGB(100,100,100)); CPen*penOld=(CPen*)pDC-》SelectObject(p1); pDC-》MoveTo(org_x,org_y); pDC-》LineTo(m_x,m_y); CPenp2(PS_SOLID,3,RGB(200,100,100)); pDC-》SelectObject(p2); pDC-》MoveTo(org_x,org_y); pDC-》LineTo(h_x,h_y);CPenp3(PS_SOLID,2,RGB(150,100,100)); pDC-》SelectObject(p3); pDC-》MoveTo(org_x,org_y); pDC-》LineTo(s_x,s_y); SetTimer(1,1000,NULL);}voidCClockView::OnTimer(UINTnIDEvent){ //TODO:Addyourmessagehandlercodehereand/orcalldefault this-》RedrawWindow(); CView::OnTimer(nIDEvent);}
易语言怎么写时钟代码
先设置好时钟间隔 (1000毫米=1秒) ,然后双击时钟进入时钟周期 输入命令即可
下面是写的简单历程:
.版本 2
.子程序 _按钮1_被单击
时钟1.时钟周期 = 100‘原本时钟周期为0,在这里设置目的是开始增加
.子程序 _时钟1_周期事件
标签1.标题 = 到文本 (到数值 (标签1.标题) + 1) ’按照时钟周期,每次周期+1
打字不容易,请采纳。 还不懂得话+我Q 481326635
怎么在电脑上设置代码时钟
1.首先单击鼠标右键,在出zhi现的选项中选择“小工具”
2.在小工具里面我们会看到一个”时钟图标“。
3.双击此图标或者鼠标放到图标上,按住拖动,即可将时钟移动到桌面上,按住时钟图标,即可移动到适合的位置。
4.鼠标放在时钟图标上,然后单击右键,在弹出的菜单中选择“选项”。
5.即可进行时钟设置,可以选择自己喜欢的样式,输入时钟上的文字。
6.完成后点击确定,即可得到自己喜欢款式的时钟了。
如何使用JS实现一个简易数码时钟
设计思路:
数码时钟即通过图片数字来显示当前时间,需要显示的图片的URL根据时间变化而变化。
a、获取当前时间Date()并将当前时间信息转换为一个6位的字符串;
b、根据时间字符串每个位置对应的数字来更改图片的src的值,从而实现更换显示图片;
构建HTML基础并添加样式。
《div id=“div1“》
《img src=’./数字时钟(1)_files/0.jpg’》
《img src=’./数字时钟(1)_files/0.jpg’》
:
《img src=’./数字时钟(1)_files/0.jpg’》
《img src=’./数字时钟(1)_files/0.jpg’》
:
《img src=’./数字时钟(1)_files/0.jpg’》
《img src=’./数字时钟(1)_files/0.jpg’》
《/div》
style样式
#div1{
width:50%;
margin:300px auto;
background:black;
}
获取图片元素以及当前时间:
var oDiv=document.getElementById(’div1’);
var aImg=oDiv.getElementsByTagName(’img’);
var oDate=new Date();
var str=oDate.getHours()+oDate.getMinutes()+oDate.getSeconds();
这里出现两个问题
1、oDate.getHours()返回的都是数字,这样编写为数字相加,而非字符串相加。
2、当获取的值为一位数时,会造成字符串的个数少于6,不满足初始设计要求。
解决以上两个问题的代码解决方案:
代码
var oDiv=document.getElementById(’div1’);
var aImg=oDiv.getElementsByTagName(’img’);
var oDate=new Date();
function twoDigitsStr()
{
if(n《10)
{return ’0’+n;}
else
{return ’’+n;}
}
var str=twoDigitsStr(oDate.getHours())+twoDigitsStr(oDate.getMinutes())+twoDigitsStr(oDate.getSeconds());
设置所有图片的src值:
for(var i=0;i《aImg.length;i++)
{
aImg[i].src=“./数字时钟(1)_files/“+str.charAt(i)+“.jpg“;
}
通过setInterval()来实现每隔1秒进行重新获取当前时间以及图片src值:
代码
var oDiv=document.getElementById(’div1’);
var aImg=oDiv.getElementsByTagName(’img’);
setInterval(function tick()
{
var oDate=new Date();
var str=twoDigitsStr(oDate.getHours())+twoDigitsStr(oDate.getMinutes())+twoDigitsStr(oDate.getSeconds());
for(var i=0;i《aImg.length;i++)
{
aImg[i].src=“./数字时钟(1)_files/“+str.charAt(i)+“.jpg“;
}
}
,1000);
但是还是有一个问题,网页在打开的初始阶段,显示时间为00:00:00,这是因为定时器有个特性,当定时器被打开后,不会立刻执行里面的函数,而是在1秒后执行。解决代码:
var oDiv=document.getElementById(’div1’);
var aImg=oDiv.getElementsByTagName(’img’);
function tick()
{var oDate=new Date();
var str=twoDigitsStr(oDate.getHours())+twoDigitsStr(oDate.getMinutes())+twoDigitsStr(oDate.getSeconds());
for(var i=0;i《aImg.length;i++)
{
aImg[i].src=“./数字时钟(1)_files/“+str.charAt(i)+“.jpg“;
}
}
setInterval(tick,1000);
tick();
问题:代码setInterval(tick,1000);中函数tick没有带括号,那么JS中函数带括号与不带括号有什么区别?
完整的数码时钟制作JS代码为:
function twoDigitsStr(n)
{
if(n《10)
{return ’0’+n;}
else
{return ’’+n;}
}
window.onload=function()
{
var oDiv=document.getElementById(’div1’);
var aImg=oDiv.getElementsByTagName(’img’);
function tick()
{var oDate=new Date();
var str=twoDigitsStr(oDate.getHours())+twoDigitsStr(oDate.getMinutes())+twoDigitsStr(oDate.getSeconds());
for(var i=0;i《aImg.length;i++)
{
aImg[i].src=“./数字时钟(1)_files/“+str.charAt(i)+“.jpg“;
}
}
setInterval(tick,1000);
tick();
}
时钟程序(C语言)怎么写
具体代码如下:
#include《graphics.h》
#include《math.h》
#include《dos.h》
#define PI 3.1415926
//屏幕中心的坐标(640X480模式下)
#define mid_x 320
#define mid_y 240
int main()
{ int graphdriver=DETECT,graphmode;
int end_x,end_y;
struct time curtime;
float th_hour,th_min,th_sec;
initgraph(&graphdriver,&graphmode,“C:\\TC2“); //初始化VGA屏幕模式
setbkcolor(BLACK); //使用黑色的背景色
while(!kbhit(0)) //若有键盘输入,则跳出,即是结束程序
{ setcolor(GREEN); //把画笔设为绿色
circle(mid_x,mid_y,180); //钟的外圆
circle(mid_x,mid_y,150); //钟的内圆
circle(mid_x,mid_y,1); //画出钟的圆心
gettime(&curtime); //取得系统当前时间
th_sec=(float)curtime.ti_sec*0.1047197551; //把秒针的角度化为弧度,为以后绘制时方便,下同
th_min=(float)curtime.ti_min*0.1047197551+th_sec/60.0; //分针的弧度
th_hour=(float)curtime.ti_hour*0.5235987755+th_min/12.0; //时度的弧度,注意整时是12等分的,所时乘的是3.14/180*5
//计算出时针的尾的坐标(时针长70)
end_x=mid_x+70*sin(th_hour);
end_y=mid_y-70*cos(th_hour);
setcolor(RED);
line(mid_x,mid_y,end_x,end_y); //用红色线画出时针
//计算出分针坐标(分针长110)
end_x=mid_x+110*sin(th_min);
end_y=mid_y-110*cos(th_min);
setcolor(RED);
line(mid_x,mid_y,end_x,end_y); //用红色画出分针
end_x=mid_x+140*sin(th_sec);
end_y=mid_y-140*cos(th_sec);
setcolor(RED);
line(mid_x,mid_y,end_x,end_y); //同上,画出秒针,长为140
//画出钟盘上的刻度,刻度长20
line(140,240,160,240); //9点对应的大刻度
line(320,60,320,80); //12点对应的大刻度
line(500,240,480,240); //3点的刻度
line(320,420,320,400); //6点的刻度
line(410,395.7,400,378.4); //5点
line(475.7,330,458.4,320); //4点
line(475.7,150,458.4,160); //2点
line(410,84.3,400,101.6); //1点
line(230,84.3,240,101.6); //11点
line(164.3,150,181.6,160); //10点
line(164.3,330,181.6,320); //8点
line(230,395.7,240,378.4); //7点
sleep(BLUE); //这里应该是打错,停止一秒,应为sleep(1000)
cleardevice(); //清除屏幕上的显示
}
closegraph(); //关闭VGA屏幕,即返回文本方式
return 0;
}
C语言编程问题,做一个控制台时钟代码是怎么写的
#include 《stdio.h》
#include 《windows.h》
int main()
{
int n;
for(i=120;i》=0;i--)
{
printf(“\r%02d:%02d“,i/60,i%60);
Sleep(1000);
}
return 0;
}
c语言怎么样编写一个时钟程序
c语言时钟程序代码如下:
#include《windows.h》
#include《math.h》
#define ID_TIMER 1//计时器ID
#define TWOPI (2*3.14159)
LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR szCmdLine,int iCmdShow)
{
static TCHAR szAppName=TEXT(“Clock“);
HWND hwnd;
MSG msg;
WNDCLASS wndclass;
wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WndProc;
wndclass.lpszClassName=szAppName;
wndclass.lpszMenuName=NULL;
wndclass.style=CS_HREDRAW|CS_VREDRAW;
if(!RegisterClass(&wndclass))
{
MessageBox(NULL,TEXT(“This program requires Windows
T“),szAppName,MB_ICONERROR);
return 0;
}
hwnd=CreateWindow(szAppName,TEXT(“Analog Clock“),WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,hInstance,NULL);
ShowWindow(hwnd,iCmdShow);
UpdateWindow(hwnd);
while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
void Setsotropic(HDC hdc,int cxClient,int cyClient)
{
SetMapMode(hdc,MM_ISOTROPIC);
SetWindowExtEx(hdc,1000,1000,NULL);
SetViewportExtEx(hdc,cxClient/2,-cyClient/2,NULL);
SetViewportOrgEx(hdc,cxClient/2,cyClient/2,NULL);
}
void RotatePoint(POINT pt,int iNum,int iAngle)
{
int i;
POINT ptTemp;
for(i=0;i《iNum;i++)
{
ptTemp.x=(int)(pt[i].x*cos(TWOPI*iAngle/360)+pt[i].y*sin(TWOPI*iAngle/360));
ptTemp.y=(int)(pt[i].y*cos(TWOPI*iAngle/360)+pt[i].x*sin(TWOPI*iAngle/360));
pt[i]=ptTemp;
}
}
void DrawClock(HDC hdc)
{
int iAngle;
POINT pt;
for(iAngle=0;iAngle《360;iAngle+=6)
{
pt.x=0;
pt.y=900;
RotatePoint(pt,1,iAngle);
pt.x=pt.y=iAngle%5?33:100;
pt.x-=pt.x/2;
pt.y-=pt.y/2;
pt.x=pt.x+pt.x;
pt.y=pt.y+pt.y;
SelectObject(hdc,GetStockObject(BLACK_BRUSH));
Ellipse(hdc,pt.x,pt.y,pt.x,pt.y );
}
}
void DrawHands(HDC hdc,SYSTEMTIME *pst,BOOL fChange)
{
static POINT pt={0,-150,100,0,0,600,-100,0,0,-150, 0,-200,50,0,0,800,-50,0,0,-200, 0,0,0,0,0,0,0,0,0,800 };
int i,iAngle;
POINT ptTemp;
iAngle=(pst-》wHour*30)%360+pst-》wMinute/2;
iAngle=pst-》wMinute*6;
iAngle=pst-》wSecond*6;
memcpy(ptTemp,pt,sizeof(pt));
for(i=fChange?0:2;i《3;i++)
{
RotatePoint(ptTemp[i],5,iAngle[i]);
Polyline(hdc,ptTemp[i],5);
}
}
LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
static int cxClient,cyClient;
static SYSTEMTIME stPrevious;
BOOL fChange;
HDC hdc;
PAINTSTRUCT ps;
SYSTEMTIME st;
switch(message)
{
case WM_CREATE:
SetTimer(hwnd,ID_TIMER,1000,NULL);
GetLocalTime(&st);
stPrevious=st;
return 0;
case WM_SIZE:
cxClient=LOWORD(lParam);
cyClient=HIWORD(lParam);
return 0;
case WM_TIMER:
GetLocalTime(&st);
fChange=st.wHour!=stPrevious.wHour||st.wMinute!=stPrevious.wMinute;
hdc=GetDC(hwnd);
Setsotropic(hdc,cxClient,cyClient);
SelectObject(hdc,GetStockObject(WHITE_PEN));
DrawHands(hdc,&stPrevious,fChange);
SelectObject(hdc,GetStockObject(BLACK_PEN));
DrawHands(hdc,&st,TRUE);
stPrevious=st;
return 0;
case WM_PAINT:
hdc=BeginPaint(hwnd,&ps);
Setsotropic(hdc,cxClient,cyClient);
DrawClock(hdc);
DrawHands(hdc,&stPrevious,TRUE);
EndPaint(hwnd,&ps);
return 0;
case WM_DESTROY:
KillTimer(hwnd,ID_TIMER);
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd,message,wParam,lParam);
}
C语言是一门通用计算机编程语言,应用广泛。C语言的设计目标是提供一种能以简易的方式编译、处理低级存储器、产生少量的机器码以及不需要任何运行环境支持便能运行的编程语言。尽管C语言提供了许多低级处理的功能,但仍然保持着良好跨平台的特性,以一个标准规格写出的C语言程序可在许多电脑平台上进行编译,甚至包含一些嵌入式处理器(单片机或称MCU)以及超级电脑等作业平台。
C语言是由UNIX的研制者丹尼斯·里奇(Dennis Ritchie)于1970年 由 肯·汤普逊(Ken Thompson)所研制出的B语言的基础上发展和完善起来的。目前,C语言编译器普遍存在于各种不同的操作系统中,例如UNIX、MS-DOS、Microsoft Windows及Linux等。C语言的设计影响了许多后来的编程语言,例如C++、Objective-C、Java、C#等。
要个简单一点的小时钟代码~
这个是文字时钟代码:
《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 seconds=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 (seconds《=9)
seconds=“0“+seconds
//change font size here
var cdate=“《small》《font color=’000000’ face=’Arial’》《b》“+dayarray[day]+“, “+montharray[month]+“ “+daym+“, “+year+“ “+hours+“:“+minutes+“:“+seconds+“ “+dn
+“《/b》《/font》《/small》“
if (document.all)
document.all.clock.innerHTML=cdate
else
document.write(cdate)
}
if (!document.all)
getthedate()
function goforit(){
if (document.all)
setInterval(“getthedate()“,1000)
}
《/script》
《body onload=“goforit()“》
《span id=“clock“》《/span》

更多文章:
易语言网页api接口怎么调用(易语言,怎么读取网页json的api)
2026年10月11日 08:00
majority of(the majority of 和 a majority of的区别以及用法例句)
2026年10月11日 07:40
another time(another time和other time的区别)
2026年10月11日 05:00








