1

I am trying to display a message for the user once they begin checking out a product past a certain time (10AM).

How would I go about doing this? Is this even possible? I'm just not sure how to catch the time from the user.

1 Answer 1

1

This can be done with the Javascript Date object. It uses the browser (device) time.

Something like the following would work

<div id="divWithWarningTextId" style="display:none;">It's past 10!</div>

<script type="text/javascript">
var time = new Date();
if (time.getHours() >= 22) {
  document.getElementById('divWithWarningTextId').style.display = 'block';
}
</script>
1
  • Sometimes stuff can be simple ;) Nov 5, 2015 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.