在JavaScript中使用时间出现问题 [英] Problem using time in JavaScript

查看:99
本文介绍了在JavaScript中使用时间出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个值为1700的变量,我想根据此变量显示时间,例如,如果值为1700,则将时间显示为5:00 PM

I have a variable with a value 1700,i want to display time on basis of this variable for eg if value is 1700 time shud display as 5:00 PM

How can this be done in javascript?

推荐答案

您提供的信息不足.当我想到为此编写程序时,会想到以下问题.

变量中值的长度是否固定?
前两位数字的值可以大于24吗?
后两位数字的值可以大于60吗?

分别考虑是",否"和否",这就是我的处理方法:

a)将变量值分成两个部分,每个部分的长度为2.
例如-将1700分为17和00.

b)如果变量1大于12,则变量1 =变量1-12.还要创建另一个变量,例如变量3,如果变量1> 12,则变量将包含"PM",否则为"AM". 例如-由于1700大于12,因此Variable1现在将包含(17-12),即5,variable3将为" PM"

c)结果值将为变量1 +:" +变量2 +" +变量3.

而已.希望您知道JavaScript中的语法.编写代码! :thumbsup:
The information you have provided is insufficient. Following questions come to my mind when I think of writing a program for this.

Is the length of the value in the variable fixed?
Can the value of first two digits be more than 24?
Can the value for last two digits be more than 60?

Considering ''yes'', ''no'', ''no'' respectively, here is how I will go about this:

a) Split the variable value into two parts each having length 2.
Ex - Split 1700 into 17 and 00.

b) If variable1 is greater than 12, then variable1 = variable1 - 12. Also create one more variable, say variable3, which will contain ''PM'' if variable1 >12 else ''AM''.
Ex - Since 1700 is greater than 12, so Variable1 will now contain (17-12) i.e 5 and variable3 will be ''PM''

c) The result value will be variable1 + ":" + variable2 + " " + variable3.

That''s it. I hope you know the syntax in JavaScript. Write the code! :thumbsup:


这篇关于在JavaScript中使用时间出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆