+ 1
want to write a JavaScript code that will look up a date day,for example if i want to know what day was 4-12-2000,pls help
9 Respuestas
+ 4
var d = new Date(prompt("Enter the Year:"), prompt("Enter the month(starting from 0):"), prompt("Enter the day:"));
var day = d.getDay();
document.write (day);
this basically takes the 3 values with a prompt from the user, if you don't understand just comment below and I will explain
+ 3
try to use getDay()
+ 3
var d = new Date(2000, 11, 4);
var day = d.getDay();
document.write (day);
pls notice that months are indexed from 0 so Dezember is 11
+ 3
window.onload = function(){
var y = new Date();
var year = document.createElement('select');
for(x= y.getFullYear();x>=1900; x--)
{
var yyyy = document.createElement('option');
yyyy.innerHTML = x;
year.appendChild(yyyy);
}
document.body.appendChild(year);
var mon = document.createElement('select');
var month = {'1':'Jan','2':'Feb','3':'Mar','4':'Apr','5':'May','6':'Jun',
'7':'Jul','8':'Aug','9':'Sep','10':'Oct','11':'Nov','12':'Dec'};
for(x= 1;x<=12; x++)
{
var mm = document.createElement('option');
mm.innerHTML = month[x];
mon.appendChild(mm);
}
document.body.appendChild(mon);
var day = document.createElement('select');
for(x= 1;x<=31; x++)
{
var dd = document.createElement('option');
dd.innerHTML = x;
day.appendChild(dd);
}
document.body.appendChild(day);
var go = document.createElement('button');
go.innerHTML = "GO";
//go.setAttribute('onclick', 'call();')
document.body.appendChild(go);
go.onclick = call;
function call(){
var sel = document.getElementsByTagName('select');
var ms = '';
for(var key in month){
if(month[key] == sel[1].value){
ms = key - 1;
}
}
let d = new Date (sel[0].value, ms, sel[2].value);
var day = d.getDay();
switch (day){
case 0:
day = "Sunday";
break;
case 1:
day = "Monday";
break;
case 2:
day = "Tuesday";
break;
case 3:
day = "Wednesday";
break;
case 4:
day = "Thursday";
break;
case 5:
day = "Friday";
break;
case 6:
day = "Saturday";
break;
}
document.write(" You Were Born On " + d + ", " + day);
}
}
+ 1
var text = "2015-1-2";
var date = new Date(text.replace(/(\d+)-(\d+)-(\d+)/, '$2/$3/$1'));
alert(date.getDay());
+ 1
Olaf I don't understand and kamil that worked,now just want to like put it in a way that the date wouldn't be fixed,that it's gonna take the users input and put it there, don't know if you understand what I'm saying
0
Thanks you guys,Kamil you wrote it all. I was actually going about it the wrong way but thank you to Helen,Olaf and Kamil and it's all not that perfect but would be glad if you guys could like check it and correct my mistakes
- 1
I've done that,
var d= new Date();
var e= d.get month();
var a,= d.getDate();
var y = d.getYear();
document.write(d);
but the stuff is showing the present date but I want it to show the date that the user is going to input,so pls how can I go about it
- 1
with Web Storage API
Storing a Value: localStorage.setItem("key1", "value1");
Getting a Value: //this will print the value
by storing u can use time settings