-3

How do I parse a date in javascript to out put a users date input to display in html in seperate lines such as:

Month:
Day:
Year:

I am using:

<button type="button" onclick="date_test()">Process</button>
<br> <p id="iop"></p>
user3004449
  • 129
  • 1
  • 15
Ed Villa
  • 69
  • 9

2 Answers2

1

Check this JSFiddle.

Code:

var dateObj = new Date();
var month = dateObj.getUTCMonth() + 1; //months from 1-12
var day = dateObj.getUTCDate();
var year = dateObj.getUTCFullYear();

document.getElementById("output").innerHTML="<p>Month:"+month+"</p><p>Day:"+day+"</p><p>Year:"+year+"</p>";

var dateObj = new Date();
var month = dateObj.getUTCMonth() + 1; //months from 1-12
var day = dateObj.getUTCDate();
var year = dateObj.getUTCFullYear();

document.getElementById("output").innerHTML="<p>Month:"+month+"</p><p>Day:"+day+"</p><p>Year:"+year+"</p>";
<div id="output">
</div>
csharpbd
  • 3,786
  • 4
  • 23
  • 32
  • Thank you for all the input on my question. csharpbd, your response was exactly what I was trying to achieve. I appreciate your time and help! – Ed Villa Apr 10 '17 at 06:34
0

var date = new Date(),
  locale = "en-us",
  month = date.toLocaleString(locale, {
    month: "long"
  }),
  day = date.toLocaleString(locale, {
    day: "numeric"
  }),
  year = date.toLocaleString(locale, {
    year: "numeric"
  });
$("#month").append(month);
$("#day").append(day);
$("#year").append(year);
.date {
  display: flex;
  flex-direction: column;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="date">
  <span id="month">Month: </span>

  <span id="day">Day: </span>

  <span id="year">Year: </span>
</div>
Geethu Jose
  • 1,953
  • 2
  • 14
  • 30