您的位置:首页 > 其它

当月的所有周日 倒计时显示当年剩下的天时分秒 公历转农历(.net)

2009-12-05 09:46 330 查看
<script type="text/javascript">
var year = new Date().getFullYear();
var month = new Date().getMonth();
var result = [];
for(var i = 1; i <= 31; i++){
var weekday = new Date(year, month, i).getDay();
if(weekday == 0 || weekday == 6 ){
result.push(i);
}
}
document.write((month + 1) + "月:" + result.join(","));
</script>

// 输入框如果输入数字自动三位三位加逗号
<script type="text/javascript">
function onKeyPrice(t)
{
var stmp = "";
if(t.value==stmp)
{
return;
}
var ms = t.value.replace(/[^\d\.]/g,"").replace(/(\.\d{2}).+$/,"$1").replace(/^0+([1-9])/,"$1").replace(/^0+$/,"0");
var txt = ms.split(".");
while(/\d{4}(,|$)/.test(txt[0]))
{
txt[0] = txt[0].replace(/(\d)(\d{3}(,|$))/,"$1,$2");
}
t.value = stmp = txt[0]+(txt.length>1?"."+txt[1]:"");
}
</script>
<input name="" type="text" onkeyup="onKeyPrice(this);" />
<asp:TextBox ID="TextBox1" runat="server" onkeyup="onKeyPrice(this);"></asp:TextBox>

//商品购买 倒计时
商品A   28天8小时6分53秒
商品b   28天8小时6分53秒
商品C   28天8小时6分53秒
商品D   28天8小时6分53秒

<div id='divs'>
<div>商品A   <span> </span> </div><br>
<div>商品b   <span> </span> </div><br>
<div>商品C   <span> </span> </div><br>
<div>商品D   <span> </span> </div></div>
<div id='CountMsg'> </div>

<script language="JavaScript">
function GetRTime(){
var EndTime= new Date("10/11/2009"); //截止时间(月 日 年)
var NowTime = new Date();
var nMS =EndTime.getTime() - NowTime.getTime();
var nD =Math.floor(nMS/(1000 * 60 * 60 * 24));
var nH=Math.floor(nMS/(1000*60*60)) % 24;
var nM=Math.floor(nMS/(1000*60)) % 60;
var nS=Math.floor(nMS/1000) % 60;
var Remain=document.getElementById("divs").getElementsByTagName('SPAN');
if(nD>= 0){
for(var i=0;i <Remain.length;i++){
Remain[i].innerHTML=nD+'天'+nH+'小时'+nM+'分'+nS+'秒';
}
}
else {
document.getElementById("CountMsg").innerHTML="时已过!";

}
setInterval("GetRTime()",1000);
}
window.onload=GetRTime;
</script>

拍卖网

剩余时间:<span id='Countdown456'></span> <br />
<script>
var liftoffTime456 = new Date(2010,5-1,28,17,0,0);
var serverdate = new Date(2010,5-1,26,16,43,56);
var localdate = new Date();
var jtime = localdate-serverdate;
liftoffTime456.setUTCSeconds(liftoffTime456.getUTCSeconds()+Math.round(jtime/1000));
$(function() {
$('#Countdown456').countdown({alwaysExpire: true, until: liftoffTime456, format: 'DHMS', timezone: +8, onExpiry:function(){ liftOff('456')} });
});
</script>

一道百度JS大面试题

题目在网页里倒计时显示当年剩下的天时分秒,格式:XX年还剩下X天X时X分X秒

(function(){
var day=hour=minitus=second=ms=0;
var year=new Date().getFullYear()+1;
var tmp=new Date(year,0,1)-new Date();
day=Math.floor(tmp/86400000);
(function(){
tmp=(new Date(year,0,1)-new Date())%86400000;
hour=Math.floor(tmp/3600000);
tmp%=3600000;
minitus=Math.floor(tmp/60000);
tmp%=60000;
second=Math.floor(tmp/1000);
ms=tmp-1000*second;

document.getElementById("m1").innerHTML="距离"+year+"年还有 "+day+" 天 "+hour+" 小时 "+minitus+" 分 "+second+" 秒 "+ms;
setTimeout(arguments.callee,50);
})();
})();

代码

//时间倒数
//parentID = "#TeamTime"
//<span id="TeamTime"><em>20</em>天<em>7</em>小时<em>3</em>分<em>2</em>秒</span>
function getLeaveTime(parentID) {
$.each(parentID, function(i, n) {
getLeavaSingleTime(n);
//alert(n);
});
return;
}

function getLeavaSingleTime(parentID) {

var tid = parentID + ">em";

if ($(tid).text()=='') {
return;
}
else {
var sec = $(tid).eq(3).text();
var min = $(tid).eq(2).text();
var hou = $(tid).eq(1).text();
var day = $(tid).eq(0).text();
if (Number(sec) > 0)
$(tid).eq(3).text(--sec);
else {
$(tid).eq(3).text(59);
if (Number(min) > 0)
$(tid).eq(2).text(--min);
else {
$(tid).eq(2).text(59);
if (Number(hou) > 0)
$(tid).eq(1).text(--hou);
else {
$(tid).eq(1).text(23);
if (Number(day) > 0)
$(tid).eq(0).text(--day);
else {
$(parentID).text("已结束");
//clearInterval(time);
}
}
}
}
}

}

function calculateCountdown() {
//The current date and time
var todaysDate = new Date();

/*The date and time of the target date in Greenwich Mean Time (year, month-1, day of month, hours in 24-hour notation, minutes, seconds, milliseconds). The "month-1" can trip you up if you're not carefully. So, for example, May is 4.*/
var targetDate = new Date(2008, 10, 25, 13, 0, 0, 0);
//var str = "2008/10/22 09:21:00";
/*The getTimezoneOffset function returns the number of minutes west of GMT the browser is. For example, a browser in the New York EST timezone would be 300 minutes off of GMT. NOTE: does not factor in Daylight Saving Time.*/
var timezoneOffset = (todaysDate.getTimezoneOffset() * 60) * 1000;

/*Factor in the time zone of the web browser before determine the time between now and the conference start time.*/
var timeDifference = (targetDate - timezoneOffset) - todaysDate;

//Now calculate the days, hours, minutes, and seconds from the time difference
var countDown = new Array(4);
countDown[0] = Math.floor((((timeDifference / 1000) / 60) / 60) / 24);
countDown[1] = Math.floor((((timeDifference / 1000) / 60) / 60) % 24);
countDown[2] = Math.floor(((timeDifference / 1000) / 60) % 60);
countDown[3] = Math.floor((timeDifference / 1000) % 60);

//Output the result
return countDown;
} //end of the calculateCountdown function

C#(ASP.NET)公历转农历的简单方法

static string SolarToChineseLunisolarDate(DateTime solarDateTime)
{
System.Globalization.ChineseLunisolarCalendar cal = new System.Globalization.ChineseLunisolarCalendar();

int year = cal.GetYear(solarDateTime);
int month = cal.GetMonth(solarDateTime);
int day = cal.GetDayOfMonth(solarDateTime);
int leapMonth = cal.GetLeapMonth(year);
return string.Format("农历{0}{1}({2})年{3}{4}月{5}{6}"
, "甲乙丙丁戊己庚辛壬癸"[(year - 4) % 10]
, "子丑寅卯辰巳午未申酉戌亥"[(year - 4) % 12]
, "鼠牛虎兔龙蛇马羊猴鸡狗猪"[(year - 4) % 12]
, month == leapMonth ? "闰" : ""
, "无正二三四五六七八九十冬腊"[leapMonth > 0 && leapMonth <= month ? month - 1 : month]
, "初十廿三"[day / 10]
, "日一二三四五六七八九"[day % 10]
);
}

使用的方法非常简单:

string 农历 = SolarToChineseLunisolarDate(DateTime.Today);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: