An warware: javascript yana canza millise seconds zuwa hh mm ss

Babban matsalar canza millise seconds zuwa sa'o'i, mintuna, da daฦ™iฦ™a shine cewa ba koyaushe suke daidaitawa ba. Misali, idan kun canza mil 10,000 zuwa sa'o'i, sakamakon zai zama sa'o'i 10. Koyaya, idan kun canza mil 10,000 zuwa mintuna, sakamakon zai zama mintuna 10 da sakan 40.

var date = new Date(milliseconds);
var hh = date.getHours();
var mm = date.getMinutes();
var ss = date.getSeconds();

Wannan lambar tana ฦ™irฦ™irar sabon abu na kwanan wata ta amfani da milliseconds da aka ba, sannan ya sami sa'o'i, mintuna, da daฦ™iฦ™a daga wannan abin kwanan wata.

Lokaci da JavaScript

JavaScript yaren shirye-shirye ne wanda ke gudana a cikin burauzar. Brendan Eich ne ya ฦ™irฦ™ira shi a cikin 1995 kuma yanzu yana ษ—aya daga cikin shahararrun yaruka akan yanar gizo.

ฦŠaya daga cikin mahimman fasalulluka na JavaScript shine ikonsa don gudanar da asynchronously. Wannan yana nufin cewa lambar na iya gudana a layi daya, wanda zai iya sa ayyuka da sauri. JavaScript kuma yana da ginannen ษ—akin karatu na kwanan wata da lokaci, wanda ke sauฦ™aฦ™a aiki tare da kwanan wata da lokuta.

Juya lokaci

Akwai ฦดan hanyoyi don canza lokaci a JavaScript. Hanyar da aka fi amfani da ita ita ce amfani da abin Kwanan wata.

var now = sabon Kwanan wata (); // 12/5/2015 3:00 PM

Hakanan zaka iya amfani da ginanniyar aikin Date.now().

var now = Kwanan wata.yanzu(); // 12/5/2015 3:00 PM

Shafi posts:

Leave a Comment