Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
318 views
in Technique[技术] by (71.8m points)

javascript - Javascript函数将日期yyyy / mm / dd转换为dd / mm / yy(Javascript function to convert date yyyy/mm/dd to dd/mm/yy)

I am trying to create a function on javascript to bring the date from my database in format (yyyy-mm-dd) and display it on the page as (dd/mm/yy).(我正在尝试在JavaScript上创建一个函数,以将数据库中的日期以(yyyy-mm-dd)格式显示并在页面上以(dd / mm / yy)显示。)

I would appreciate any help.(我将不胜感激任何帮助。)

Thanks.(谢谢。)

PD: Let me know if you need more clarification.(PD:让我知道您是否需要更多说明。)

  ask by Amra translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you're sure that the date that comes from the server is valid, a simple RegExp can help you to change the format:(如果您确定来自服务器的日期有效,则简单的RegExp可以帮助您更改格式:)

function formatDate (input) {
  var datePart = input.match(/d+/g),
  year = datePart[0].substring(2), // get only two digits
  month = datePart[1], day = datePart[2];

  return day+'/'+month+'/'+year;
}

formatDate ('2010/01/18'); // "18/01/10"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...