简体   繁体   中英

How to wear year, month and date from ISO?

How to wear year, month and date from ISO?

From the backend I get a date in ISO format:

birthdate: '09-09-1990'

Prior to this, when the date came in a date format, I did this:

const birthDate = new Date(user.birthdate)
const day = birthDate.getDate().toString()
const month = birthDate.getMonth() + 1
const year = birthDate.getFullYear()

The format that you specified is not an ISO format. However for the format specified, you can directly get year, day and month by splitting. You can try below for such strings. You may see if it help you

var str = '09-09-1990'
  var res = str.split("-");
  var day = res[0]
  var month = res[1]
  var year = res[2]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM