Convert date into word format

后端 未结 5 1622
醉话见心
醉话见心 2021-01-28 05:42

I\'m not sure how i will do it, I want convert date in english word format, like this if date is 10-10-1988 then

In English- tenth October nineteen eighty eight
         


        
5条回答
  •  遥遥无期
    2021-01-28 06:27

    Something like that

    var wDays = ['first', 'second', 'third', 'fourth', 'fifth', 'sixth', '	seventh', 'eighth', 'ninth', 'tenth', 'eleventh', 'twelfth', 'thirteenth', 'fourteenth', 'fifteenth', 'sixteenth', 'seventeenth', 'eighteenth', 'nineteenth', 'twentieth', 'twenty-first', 'twenty-second', 'twenty-third', 'twenty-fourth', 'twenty-fifth', 'twenty-sixth', 'twenty-seventh', 'twenty-eighth', 'twenty-ninth', 'thirtieth', 'thirty-first']
    
    var wMonths = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
    var wNumbers = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty', 'twentyone']
    
    var date = new Date()
    var day = parseInt(date.getUTCDate()) - 1;
    var month = parseInt(date.getUTCMonth());
    var year = date.getUTCFullYear().toString();
    
    var x = year.charAt(0)
    var xx = year.charAt(1)
    var xxx = year.charAt(2)
    var xxxx = year.charAt(3)
    
    
    var a = parseInt(x + xx) - 1
    var b = parseInt(xxx) - 1
    var c = parseInt(xxxx) - 1
    console.log(wDays[day] + ' ' + wMonths[month] + ' ' + wNumbers[a] + ' ' + wNumbers[b] + ' ' + wNumbers[c])

提交回复
热议问题