Could you give me a javascript showing only the year in the Japanese calendar?
document.write(date.toLocaleDateString("ja-JP-u-ca-Japanese"));
I thought so, but I don't think so.
Thank you for your cooperation.
javascript
Could you explain "I don't think so"?
If you simply want to take out the year part, you can use substring
and indexOf
to cut out /
as follows:
var date=new Date();
date=date.toLocaleDateString("ja-JP-u-ca-Japanese");
var year=date.substring(0,date.indexOf("/"));
document.write(year);
The second argument of toLocaleDateString
should be era
.
date.toLocaleDateString("ja-JP-u-ca-Japanese", {era: "long"})
However, with this designation on Edge, it will be 28/02/24
and the era name will not be printed.I don't know if this is a specification or a bug, but in order to get Heisei
, the option must not include day
.
date.toLocaleDateString("ja-JP-u-ca-Japanese", {era: "long", year: "numerical", month: "numerical"})
If it is automatically updated, you can do the following:
<script language="javaScript">
<!--
var now = new Date();
var Wareki=now.getYear();
if(Wareki>1000) {Wareki-=1900;}
Wareki-=88;
document.write("<font style='font-size:30px;color:red'>");
document.write ("Heisei this year");
document.write(Wareki);
document.write("year");
document.write("is </font>");
// -- >
</script>
Note: http://tsunamiblog.blog60.fc2.com/blog-entry-74.html
© 2024 OneMinuteCode. All rights reserved.