Custom dateFormat like "dd-mm-yyyy" doesn't work properly if device follows japanese/buddhist calendar

In swift if using custom dateFormat like "dd-mm-yyyy" and device follows japanese calendar now get dateForm dateFormatter , expected "30-05-Reiwa6". but dateFormatter return string is "30=05-0006"

Answered by DTS Engineer in 789149022

Expanding on jlilest’s answer a bit…

This post explains the three recommended ways to use DateFormatter. Please try out the one that best suits your needs. If you follow-up questions, reply back here with the details and I’ll take a look.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

The format strings are designed for the Gregorian calendar. If this is meant to be shown to the user, you should an appropriate localized format.

Expanding on jlilest’s answer a bit…

This post explains the three recommended ways to use DateFormatter. Please try out the one that best suits your needs. If you follow-up questions, reply back here with the details and I’ll take a look.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Formats containing specific fields, by passing those fields to DateFormatter.dateFormat(fromTemplate:options:locale:) and then applying the resulting string to the dateFormat property of your date formatter
above method works But i set "dd-mm-yy" or "dd.mm.yy" in template but it return "dd/mm/yy" format String

Right. When you apply a template, it ignores all the ‘punctuation’ and focuses solely on the tokens. This makes sense when working with localised dates.

With reference to the post I mentioned, are you trying to create:

  • A localised date?

  • Or a fixed-format date?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Custom dateFormat like "dd-mm-yyyy" doesn't work properly if device follows japanese/buddhist calendar
 
 
Q