The question is published on by Tutorial Guruji team.
I need to display the current date on my webpage using jquery or javascript, sounds easy right?
However I would like the date to be displayed in roman numerals (d/m/y format). eg: 13/10/2013 to be displayed as XIII.X.MMXIII
I have been trying for a few days now but everything I try won’t work. I have a fairly limited knowledge of jquery and javascript, I only know how to do normal date. Like this:
<script type="text/javascript"> <!-- var currentTime = new Date() var month = currentTime.getMonth() + 1 var day = currentTime.getDate() var year = currentTime.getFullYear() document.write(month + " . " + day + " . " + year) //--> </script>
If anyone can help me to display the date in roman numerals it would be greatly appreciated.
Thank you.
Answer
Use one of the roman numeral converter discussed in this question Convert a number into a Roman Numeral in javaScript. By example, the one from http://blog.stevenlevithan.com/archives/javascript-roman-numeral-converter:
function romanize (num) { if (!+num) return false; var digits = String(+num).split(""), key = ["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM", "","X","XX","XXX","XL","L","LX","LXX","LXXX","XC", "","I","II","III","IV","V","VI","VII","VIII","IX"], roman = "", i = 3; while (i--) roman = (key[+digits.pop() + (i * 10)] || "") + roman; return Array(+digits.join("") + 1).join("M") + roman; }
Then you can do:
var currentTime = new Date(); var strRomanDate = romanize(currentTime.getMonth() + 1) + " . " + romanize(currentTime.getDate()) + " . " + romanize(currentTime.getFullYear()) + 1;