Text DateStyle with short month name in SwiftUI - swift

The following outputs the complete month name, e.g. July 11, 2022
Text("\(Date().now, style: .date)") // output: July 11, 2022
Is there a way to make it show just the short month name, e.g. Jul 11, 2022 or 06/11/22?

Show current date without time in a short format.
//Jul 11, 2022
Text(Date().formatted(date: .abbreviated, time: .omitted))
//7/11/2022
Text(Date().formatted(date: .numeric, time: .omitted))

SwiftUI 3+
We have now explicit initializer for that, like
Text(Date.now, format: Date.FormatStyle(date: .abbreviated, time: .omitted))

Related

UIDatePicker modal view show incorrect (last) month

My UIDatePicker (with style .compact) is set to Today by default, and always in timezone UTC.
cell.datePicker.subviews[0].backgroundColor = nil
cell.datePicker.backgroundColor = .secondarySystemGroupedBackground
cell.datePicker.timeZone = TimeZone(identifier: "UTC")
cell.datePicker.date = flight.date
cell.datePicker.addTarget(self, action: #selector(handleDatePicker(sender:)), for: UIControl.Event.valueChanged)
After clicking on the textfield "Jan 11, 2023", it will show a calendar-style editor. However, the date was set to today (Jan 11, 2023), but it shows the month of "December 2022" initially.
After I click the arrow (next month), the date (Jan 11) was pre-selected correctly.
The expected behavior should be after clicking the text "Jan 11, 2023", the month of "Jan 2023" is shown with Jan 11 pre-selected.
This bug can only be re-produced if the date is set to "today", but the UTC date and the local date are different.
For example, I'm in UTC+8 timezone. The date is set to "2023-01-11 17:30:00 +0000". When the UTC time is Jan 11, 2023 17:30Z, and the local time is Jan 12, 2023 01:30L. It will show "December 2022" when the modal view first shown.

How to convert text to date format in google sheet?

In my google sheet I have a column with dates but its in a text format. here an example what I have:
Oct 01, 2021
Dec 25, 2020
...
...
I want to convert it to a date format
01/10/2021
25/12/2020
....
I need to find the number of days from the dates in this column, by using "date in column" - now(). This does not work with the format "Oct 01, 2021" since its a text, and I am getting an error from Googlesheet.
Thanks in advance
IS
Try this formula in F2:
=ARRAYFORMULA(IFERROR(DATEDIF(
DATE(
RIGHT(E2:E,4),
MATCH(LEFT(E2:E,3),{"Jan";"Feb";"Mar";"Apr";"May";"Jun";"Jul";"Aug";"Sep";"Oct";"Nov";"Dec"},0),
MID(E2:E,5,2)),
NOW(), "D")))
Update
Revised the formula, which goes in F1 and fills the column, to:
={"Days Left";ARRAYFORMULA(
IFERROR(-1 * DATEDIF( DATE( RIGHT(E2:E,4), MATCH(LEFT(E2:E,3),{"Jan";"Feb";"Mar";"Apr";"May";"Jun";"Jul";"Aug";"Sep";"Oct";"Nov";"Dec"},0), MID(E2:E,5,2)), NOW(), "D"),
IFERROR(DATEDIF( NOW(),DATE( RIGHT(E2:E,4), MATCH(LEFT(E2:E,3),{"Jan";"Feb";"Mar";"Apr";"May";"Jun";"Jul";"Aug";"Sep";"Oct";"Nov";"Dec"},0), MID(E2:E,5,2)), "D"))))}
which reverses the date difference values. It also handles date differences for dates either in the future, or in the past.
Use the DATEVALUE() function on a date string, then use DATEDIF() to find the difference between two dates.
=DATEDIF(DATEVALUE("Oct 01, 2020"), DATEVALUE("Dec 25, 2020"), "D")
UPDATE: To find the date between today and a date string in another cell use this example:
=DATEDIF(DATEVALUE(A2), NOW(), "D")
If cell A2 contains string Oct 01, 2020, it will return 70 for today 2020-12-10

Printing in console Date() giving incorrect current time [duplicate]

This question already has answers here:
NSDate() or Date() shows the wrong time
(2 answers)
Closed 4 years ago.
I created an object that has a creation date property. The date property is calculated by using the Date() function, for getting the current date and time.
The date is correct but the time is 3 hours behind the clock of the simulator. How can I fix this?
The system displays the current date / time of UTC/GMT.
To get time/date for local time zone. use following code:
let currentDate = Date()
//7/29/18, 9:09 PM
print (DateFormatter.localizedString(
from: currentDate,
dateStyle: .short,
timeStyle: .short))
//Sunday, July 29, 2018 at 9:09:27 PM India Standard Time
print (DateFormatter.localizedString(
from: currentDate,
dateStyle: .full,
timeStyle: .full))
//Jul 29, 2018 at 9:09:27 PM
print (DateFormatter.localizedString(
from: currentDate,
dateStyle: .medium,
timeStyle: .medium))
Above code is tested in India at 09:09 PM on 29th July 2018.

Why does ColdFusion Format Dates Differently using the same function

Consider the following code:
<cfset lateDate = createDate(2014,12,8) />
<cfset currentdate = createDate(2015,4,15) />
<cfdump var="#lateDate#" />
<cfdump var="#currentdate#" />
<cfdump var="#dateCompare(currentdate,lateDate)#" />
Output on my machine is:
{ts '2014-12-08 00:00:00'} {ts '2015-04-15 00:00:00'} 1
Question 1: Why is the month switched on the two dates. (month/day). The spec says create date is yyyy,mm,dd and yet either CF switched them or it's displaying them switched.
It's doing the dateCompare correctly so what is going on. Have I been staring at this too long?
I think you have been looking at it too long. Both of those are valid dates and the month is not being switched. One of your dates is April 15, 2015 and the other is December 8, 2014. I assume you were thinking August 12, 2014 for that date. Then your code should be createDate(2014,8,12). Right?
The dateCompare function only tells you if the first date is earlier or later than the second date. For both of your dates, the correct one and your assumed one, the first date is later than the second.
I think the code is working correctly. As in:
createDate(2014,8,12) <!--- August 12, 2014 --->
createDate(2014,12,8) <!--- December 8, 2014 --->
createDate(2015,4,15) <!--- April 15, 2015 --->
dateCompare "April 15, 2015" "December 8, 2014" returns 1
dateCompare "April 15, 2015" "August 12, 2014" returns 1

How to format a date in Ext JS 3?

I have a date value like this ;
Date {Fri Feb 13 2015 02:00:00 GMT+0200 (GTB Standart Saati)}
I get it from a grid column with ;
selectionModel.getSelected().data['date'];
And column model date format is 'd/m/Y'. It shows in grid well (d/m/Y).But when i get selected value it returns a date format doesn't like 'd/m/Y'. How can i format this date to set to a textfield ?
According to ExtJs Docs
var d = new Date(1993, 6, 28, 14, 39, 7);
println(d.toString()); // prints Wed Jul 28 1993 14:39:07 GMT-0600 (PDT)
println(d.toDateString()); // prints Wed Jul 28 1993
Edit:
Please use Ext.Date.format to format the date:
Ext.Date.format(d,'d/m/Y');
According to ExtJS 3.4 Docs Date object is extended with .format() method.
So you should be able to just do
var d = new Date();
d.format("d/m/Y");