我到处寻找一个简单的函数来将日期(在我的例子中,由 Google 表单给出)转换为合同中使用的序数格式:
即2018年5月25日
有一个人提出了这个问题,其他人将其标记为重复,然后引用了另一个根本没有回答他的问题的答案!所以对于那些需要这个的人来说 - 这是一个简单的函数:
function ordinal(date) {
var d = date.getDate();
var month = new Array ();
month[0] = "January";
month[1] = "February";
month[2] = "March";
month[3] = "April";
month[4] = "May";
month[5] = "June";
month[6] = "July";
month[7] = "August";
month[8] = "September";
month[9] = "October";
month[10] = "November";
month[11] = "December";
var m = month[date.getMonth()];
var y = date.getYear();
return d + (d > 0 ? ['th', 'st', 'nd', 'rd'][(d > 3 && d < …Run Code Online (Sandbox Code Playgroud) javascript ordinal google-sheets date-formatting google-apps-script