How to show XX minutes ago by Dynamic in my widget without second string?

Learning Keeping a Widget Up To Date I know I can show Text with a dynamic time, but It's a fixed format like 32sec or 2 hours 23 minutes


How can I just show "23 minutes ago" without second string?

Thanks for help me
Look into incorporating dateformat and date() in your code. Something like:

Code Block
let formatter = Date()
formatter.dateformat = “mm”
Text(“\(mm) minutes ago”)”

That may not be the exact cod, but it should get you on the right track.

Thank you for your reply @ CPSoftware 

But My need is to show this text dynamic changed by system like Text("\(now, style: .timer) ago")

Using your func just show 2m ago will not change by increasing
Hi,

You can use RelativeDateTimeFormatter generating your own string to show:

Code Block
return RelativeDateTimeFormatter().localizedString(for: updated, relativeTo: Date())

Where updated is a Date.

Or in the View itself, using a Text view (update is again a Date):

Code Block
Text(updated, style: .relative)


Just to clarify, there is no way to pass formatting options into the style parameter right?
I'm also want to know how to format the date like this
How to show XX minutes ago by Dynamic in my widget without second string?
 
 
Q