I have a quick question.. I am using website builder called 'clickfunnels', and they dont support feature that would allow me to display current date via website. But, I can add custom html to it...
With that said, I found an old Stack Overflow question which is very close to fixing my problem, but this person wanted the current date to show +1 or the next day than the current date.
Here is the coding I tried, which works perfect on the website, I just need it to show the current date and not +1.
Can anyone please give me some tips on editing this? It would be greatly appreciated!!! Thank You!
<span id="spanDate"></span>
<script type="text/javascript">
var months =
['January','February','March','April','May','June','July',
'August','September','October','November','December'];
var tomorrow = new Date();
tomorrow.setTime(tomorrow.getTime() + (1000*3600*24));
document.getElementById("spanDate").innerHTML =
months[tomorrow.getMonth()] + " " + tomorrow.getDate()+ ", " +
tomorrow.getFullYear();
</script>
Just remove (1000*3600*24) from tomorrow. It is adding extra day
var months =
['January','February','March','April','May','June','July',
'August','September','October','November','December'];
var tomorrow = new Date();
tomorrow.setTime(tomorrow.getTime());
document.getElementById("spanDate").innerHTML =
months[tomorrow.getMonth()] + " " + tomorrow.getDate()+ ", " +
tomorrow.getFullYear();
<span id="spanDate"></span>
Just remove the setTime line
<span id="spanDate"></span>
<script type="text/javascript">
var months =
['January','February','March','April','May','June','July',
'August','September','October','November','December'];
var tomorrow = new Date();
/* tomorrow.setTime(tomorrow.getTime() + (1000*3600*24)); */
document.getElementById("spanDate").innerHTML =
months[tomorrow.getMonth()] + " " + tomorrow.getDate()+ ", " +
tomorrow.getFullYear();
</script>
Related
I'm to figure out how to code so that the link opens into a new window? Is this the correct way to do that?
<script>
var copyright = "© ";
var d = new Date();
var n = d.getFullYear();
var db = " Doing Business";
var str = new String(" Link");
document.write(copyright + n + str.link("https://www.google.com"));
document.write(db);
</script>
Please stop using String.link. It's old, deprecated, and smelly. It also doesn't support what you are trying to do.
You can construct a link with the appropriate target attribute (read more) to open in a new tab as follows:
var myLink = "<a target='_blank' href='https://www.google.com'>Link</a>";
document.write(copyright + n + " " + myLink);
I am using moment.js in date range picker I want to hide or disable my minutes hand. What can i do, here is my code which I tried :
function cb(start, end) {
$('#reportrange span').html(start.format('YYYY-MM-DD hh') + ' - ' + end.format('YYYY-MM-DD hh'));
$('#hidreportrange').val(start.format('YYYY-MM-DD hh'));
var selecteddate = start.format('YYYY-MM-DD hh');
var con = new Date(selecteddate);
var datestring = con.toString();
$("#spnseldate").html(datestring.split(" ")[2] + " " + datestring.split(" ")[1] + " " + datestring.split(" ")[3]);
// $("#spncurrentDate").html(DataBaseManager.DateTimeFormat(start.format('YYYY-MM-DD')));
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>
<script>
function abc(start,end){
console.log(moment(start).format('MM-DD-YYYY HH:mm:ss'),moment(end).format('DD-MM-YYYY HH:mm:ss'));
}
abc(new Date(),new Date());
</script>
you can use like that if you are using moment.js then you have to pass your date
in that function.
I have an element on my website that is hosted externally and referenced in a script on my page.
I want to automatically change the text within this content so that it always displays tomorrow's date.
Script for the widget:
<script src="//my.externalwidget.com/12345.js" type="text/javascript" charset="utf-8" async="async"></script>
HTML contained in external script:
<div id="changeHeaderOne">THIS SHOULD DISPLAY TOMORROW'S DATE</div>
My JS:
<script type="text/javascript">
var currentDate = new Date(new Date().getTime() + 24 * 60 * 60 * 1000);
var dateParse = currentDate.toString();
var dayAbbr = dateParse.substr(0, 3);
var day = currentDate.getDate();
var month = currentDate.getMonth() + 1;
var year = currentDate.getFullYear();
document.getElementById("changeHeaderTwo").innerHTML = "Tomorrow's date is " + dayAbbr + " " + month + "/" + day + "/" + year;
document.getElementById("changeHeaderOne").innerHTML = "Tomorrow's date is " + dayAbbr + " " + month + "/" + day + "/" + year;
I know my script is working because it runs properly on #changeHeaderTwo (located in DOM) but not on #changeHeaderOne (externally hosted and loaded using the script on top).
Any ideas how to make this apply to the externally loaded code as well?
You are using document.getElementByClass() (which should really by document.getElementsByClassName()) when your div has an id. Use document.getElementById() instead.
How to check time conditionin Jquery
var startTime="20:02:55"; // or 12:34
var endTime ="21:02:55" // or 1:34
var dt = new Date();
var time = dt.getHours() + ":" + dt.getMinutes() + ":" + dt.getSeconds();
if(time >startTime || time < endTiime){
$("#a").html("show Box");
}else{
$("#a").html("Expire BOx");
}
How to check 12 hour and 24 hour condition also?
is it correct? i need am, pm format check please can anyone help me?
Here is some code. I am appending to show both behaviour.
Here is DEMO
test("20:02:55", "21:02:55");
test("13:02:55", "15:02:55");
function test(start_time, end_time) {
var dt = new Date();
//convert both time into timestamp
var stt = new Date((dt.getMonth() + 1) + "/" + dt.getDate() + "/" + dt.getFullYear() + " " + start_time);
stt = stt.getTime();
var endt = new Date((dt.getMonth() + 1) + "/" + dt.getDate() + "/" + dt.getFullYear() + " " + end_time);
endt = endt.getTime();
var time = dt.getTime();
if (time > stt && time < endt) {
$("#a").append("<br> show Box ");
} else {
$("#a").append("<br> Expire BOx ");
}
}
Try this.
I took the logic to print 'Show Box' if the current time is in between the start and end time. else viceversa.
var startTime="20:02:55"; // or 12:34
var endTime ="21:02:55" // or 1:34
var dt = new Date();
var st = new Date('00','00','00',startTime.split(':')[0],startTime.split(':')[1],startTime.split(':')[2]);
var et = new Date('00','00','00',endTime.split(':')[0],endTime.split(':')[1],endTime.split(':')[2]);
if(dt.getTime() >st.getTime() && dt.getTime() < et.getTime()){
alert("show Box");
}else{
alert("Expire BOx");
}
I have a JavaScript code to get new time. But when i reload the page the time doesn't change instead it says 1/10/2014 10:57, how can i add a function for the time and date to detect and change
Below is the code I tried but its not working.
<script type="text/javascript">
(function () {
// using current UTC time from server as ref, display local time in div id="now"
var now = new Date();
now.setTime(1389322677492);
var nowstr = ""
+ (now.getMonth() + 1) + "/"
+ now.getDate() + "/"
+ ((now.getYear() < 1000) ? now.getYear() + 1900 : now.getYear()) + " "
+ now.getHours() + ":"
+ ((now.getMinutes() < 10) ? '0' + now.getMinutes() : now.getMinutes());
var el = document.getElementById("now");
el.appendChild(document.createTextNode(nowstr));
})();
</script>
Thanks for helping me.
Thats because you are explicitly setting it to 1389322677492 everytime. All you need to do is remove the line:
now.setTime(1389322677492);