Dates seem to be my new nemesis

Sorry for asking numerous questions lately. I have been searching for answers but cant seem to get it right.

I want to create a date picker and then format the date picked. I can pick but can seem to figure out how to formate with DateFormatter().


let bdate = await showDatePicker()
console.log(bdate)

async function showDatePicker() {
  let picker = new DatePicker()
  let bdate = await picker.pickDate()
  return bdate
}

let format = new DateFormatter(bdate)
let formatted = format.useShortDateStyle()
console.log(formatted)

I haven’t gotten to this but then will want to calculate the time between date picked and another. If difference less than a year will want to display in months, but if greater than 1 year will want to display in years and months

You’re not alone! Dates are the bane of developers and Automators everywhere!


let bdate = await showDatePicker()
console.log(bdate)

async function showDatePicker() {
  let picker = new DatePicker()
  let bdate = await picker.pickDate()
  return bdate
}

let format = new DateFormatter()
let formatted = format.useShortDateStyle()
console.log(format.string(bdate))

let yearMonthFormatter = new DateFormatter()
yearMonthFormatter.dateFormat = "MM/yyyy"

let monthFormatter = new DateFormatter()
monthFormatter.dateFormat = "MM"


console.log(yearMonthFormatter.string(bdate))
console.log(monthFormatter.string(bdate))

1 Like