如何解析javascript中的日期以将用户日期输入放在html中以单独的行显示,例如:
月份:
日:
年份:
我正在使用:
<button type="button" onclick="date_test()">Process</button>
<br> <p id="iop"></p>
答案 0 :(得分:1)
选中JSFiddle。
代码:
if tableView == nil {
var tableView = UITableView()
tableView.dataSource = self
tableView.delegate = self
tableView.backgroundColor = UIColor.black
tableView.alpha = 0.9
tableView.x = cityBtn.x
tableView.y = cityBtn.frame.maxY
tableView.width = cityBtn.width
tableView.heigth = 0
tableView.layer.cornerRadius = 10
addSubview(tableView)
tableView = tableView
}
return tableView
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>";
&#13;
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>";
&#13;
答案 1 :(得分: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);
&#13;
.date {
display: flex;
flex-direction: column;
}
&#13;
<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>
&#13;