<head>
<title>js倒计时</title>
<script type="text/javascript">
var total=2*3600;//总共多少秒
function showTime()
{
total--;
var hour=total/3600;
var sec=(total%3600)/60;
var min=(total%3600)%60;
document.getElementById("divId").innerHTML="还有"+hour+"小时"+sec+"分"+min+"秒";
if(total>0)
{
setTimeout("showTime()",1000);//每一秒钟执行一次检查
}
else
{
document.getElementById("divId").innerHTML="活动已结束!";
}
}
</script>
</head>
<body>
<div id="divId"></div>
</body>
public partial class FormTime : Form
{
public FormTime()
{
InitializeComponent();
}
private void FormTime_Load(object sender, EventArgs e)
{
timerMain.Enabled = true;
timerMain.Interval = 1000;
timerMain.Start();
}
private void timerMain_Tick(object sender, EventArgs e)
{
DateTime observeTime = DateTime.Parse("2023-11-22 22:45:30");//倒计时日期
DateTime now = DateTime.Now; //当前时间
TimeSpan ts = observeTime.Subtract(now); //两个时间之差
StringBuilder result=new StringBuilder(); //存放结果
int year=observeTime.Year - now.Year; //得到相差的年
int month = observeTime.Month - now.Month; //得到相差的月
int day = observeTime.Day - now.Day; //得到相差的日
int hmh=(observeTime.Hour-now.Hour)*3600+(observeTime.Minute-now.Minute)*60+(observeTime.Second-now.Second);
//如果时分秒比现在的时间晚
if(hmh<=0)
{
//向日借一
day--;
if((day<=0&&month>0)||(day<=0&&year>0))
{
//如果天数小于0向月借一
day=GetDay(now.Year, now.Month)- now.Day + observeTime.Day;
month--;
if(month<0&&year>0)
{
//如果月数小于0,向年借一,同时把月专为正数
month += 12;
year--;
}
}
}
//如果天数小于0向月借一
if ((day < 0 && month > 0) || (day < 0 && year > 0))
{
day = GetDay(now.Year, now.Month) - now.Day + observeTime.Day;
month--;
if (month < 0 && year > 0)
{
//如果月数小于0,向年借一,同时把月专为正数
month += 12;
year--;
}
}
//如果月数小于0,向年借一,同时把月专为正数
if (month < 0 && year > 0)
{
month += 12;
year--;
}
if (year<0||(year == 0 && month < 0)||(year == 0 && month==0&&day<0))
{
lblShow.Text = "已超过日期";
return;
}
if (year> 0)
{
result.Append(year+ "年");
}
if (month> 0)
{
result.Append(month+ "月");
}
if (day> 0)
{
result.Append(day+ "天");
}
if (ts.Hours > 0)
{
result.Append(ts.Hours + "时");
}
if (ts.Minutes > 0)
{
result.Append(ts.Minutes + "分");
}
if (ts.Seconds > 0)
{
result.Append(ts.Seconds + "秒");
}
if(result.Length==0)
{
result.Append("已超过日期");
}
lblShow.Text = result.ToString();
}
//输入月份后获得该月天数
private int GetDay(int year, int month)
{
int result = 31;
switch (month)
{
case 4:
case 6:
case 9:
case 11:
result = 30;
break;
case 2:
if ((year % 100 != 0) && (year% 4 == 0) || (year% 400 == 0))
{
result = 29;
}
else
{
result = 28;
}
break;
}
return result;
}
}
C# 的定时器的实现方法有 3 种: (1)使用 System.Windows.Forms.Timer (2)使用 System.Threading.Timer (3)使用 System.Timers.Timer 其中: System.Windows.Forms.Timer 只能在 WinForm 中使用,通过...
System.Threading.Timer 是一个简单的轻量计时器,它使用回调方法并由线程池线程提供服务。在必须更新用户界面的情况下,建议不要使用该计时器,因为它的回调不在用户界面线程上发生。在此类情况下,System.Windows...
多线程计时器 1:System.Threading.Timer 2:System.Timers.Timer 特殊目的的单线程计时器: 1:System.Windows.Forms.Timer(Windows Forms Timer) 2:System.Windows.Threading.DispatcherTimer(WPF ti
按照你的说法,用timer最符合你的要求。在Global文件的Application_Start中创建一个timer, System.Timers.Timer timer = new System.Timers.Timer(); timer.Enabled = true; timer.Interval = 60000;//执行间隔时间...
不过大部分也不是太实用,我觉得Timer控件还算比较有用,因此再把它做成个程序用一下。 其实程序大体是网上查到的,不过有些错误,我修改了一下。程序如下: private void timer2_Tick(obje
winform之单线程使用Timer计时器让窗口在几秒后自动关闭
实现按用户定义的时间间隔引发事件的计时器。此计时器最宜用于 Windows 窗体应用程序中,并且必须在窗口中使用。 System.Windows.Forms.Timer // 2.提供以指定的时间间隔执行方法的机制。无法继承此类。 ...
private void button2_Click(object sender, EventArgs e) { Form1 frmShowWarning = new Form1();//Form1为要弹出的窗体(提示框), Point p = new Point(Screen.PrimaryScreen.WorkingArea.Width-f
winform C#屏幕右下角弹出消息框并自动消失
ASP.NET中的三种Timer(计时器)的区别和用法卡卡 发表于 2014/12/5 13:02:00 | 分类标签: Timer 计时器 ASP.NET NET中有3个不同的定时器。这3个定时器分别是: 1.实现按用户定义的时间间隔引发事件的计时器。此计时...
在一个用户界面中,要求用户提供一个Excel文件的地址,用户界面如下。 ...如果这个过程时间很长的话,就会造成用户界面的假死现象,没有任何动静。所以,一般会在Form中用一个正在等待的GIF图片提示用
一、使用计时器在某些情况下,可能不需要使用单独的线程。如果应用程序需要定期执行简单的与 UI 有关的操作,则应该考虑使用进程计时器。有时,在智能客户端应用程序中使用进程计时器,以达到下列目:• 按计划定期...
一:windows窗体程序设计 (1)窗体创建的几种方式 using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace WindowsForms... static class Program
这两天正在准备做一个实时控制的东西,想用C#。可是昨天日本人展示了一个在LINUX平台下使用C语言控制的单自由度机械臂,我问他们为什么不用WINDOWS,他们说用WINDOWS编程实时性很差,定时很不准,所以用了LINUX,...
1 调用WIN API中的GetTickCount [DllImport("kernel32")] static extern uint GetTickCount(); 从操作系统启动到现在所经过的毫秒数,精度为1毫秒,经简单测试发现其实误差在大约在15ms左右 ...
因为需要每天定时(晚上九点)把数据插入到数据库中,所以决定写成一个windos 服务。 参考文档:http://dev.firnow.com/course/4_webprogram/asp.net/asp_netshl/2008414/110334.html 1。在VS2008创建windows ...
这是我在《电脑编程技巧与维护》上发表的第七... 摘 要:本文详细论述了在幻灯片中运用VBA进行轻量级应用程序开发的方法和技巧。 关键词:幻灯片 VBA 在企事业单位上我们经常能见到一些知识抢答赛之类的应用,...
前言: 定时器的作用就是每隔一个指定的时间,调用一次,和Tick事件...在用到vs 2005的兴奋过程中,想给程序做个启动画面,我采用了显示Aform,过一段时间,隐藏这个Aform,showdialog下一个Bform,closeAForm这个
多线程计时器 1:System.Threading.Timer 2:System.Timers.Timer 特殊目的的单线程计时器: 1:System.Windows.Forms.Timer(Windows Forms Timer) 2:System.Windows.Threading.DispatcherTimer(WPF
本文记录 百度地图实现实现 轨迹回放的功能。 所谓轨迹回放功能。 是指选择某个时间段,然后在地图上再现这个时间段内轨迹的出现情况。 什么时候出现了第几个轨迹点。隔几秒出现下一个轨迹 点。
public class ProcessCount { private Int32 _TotalSecond; public Int32 TotalSecond { get { return _TotalSecond; } set { _TotalSecond = value; } ...
背景: 要学习使用一个新东西,我们必须知道他是个什么东西。对于我们此次研究的windows服务来说,他又是个什么东西,其实也没有什么高深的了。 windows service概述: 一个Windows服务程序是在Windows操作...
timeLabel =[[UILabel alloc] initWithFrame:CGRectMake(0, objV.frame.size.height-39, iPhoneWidth, 39)]; // 创建一个NSTimer类 [NSTimer scheduledTimerWithTimeInterval:0.01 ...sele
JavaScript运行原理 单线程 JS引擎 执行栈 任务队列 同步、异步
ApplicationsCrafting a C# forms Editor From scratchhttp://www.codeproject.com/csharp/SharpFormEditorDemo.asp建立一个类似C#的环境, 实现控件拖拉,属性 Packet Capture and Analayzer网络封包截获...
背景:一位老程序员,有十年的从业经验,不敢说精通,不过可以算熟练VB/VC++,其他Java/Pascal等语言都略有所知,现在因为项目需要,同时也是与时俱进,开始学习C#语言,平台使用Visual Studio 2008。 也许好多...
在工作中经常会遇到需要将一组数据绘制成曲线图的情况,最简单的方法是将数据导入Excel,然后使用绘图功能手动生成曲线图。但是如果基础数据频繁更改,则手动创建图形可能会变得枯燥乏味。本篇将利用...
在做项目时,遇到同步ERP数据的问题,客户要求是:在程序中,设置一个开始时间,再设置一个时间间隔,让程序每隔一段时间导出销售记录,这个开始时间和时间间隔可以手动修改设定。 这问题纠缠了我好几天,总算解决...
System.Timers
.NET Conf China 2020讲师 PDF