SwiftUI Widget DateStyle Custom Format - swift

Just wondering if there is a way to apply a custom format for the DateStyle comp within SwiftUI's Text UI. For Example just the minutes or seconds like you would when using a DateFormatter. I want to display the dynamic dates for a Widget but it only offers a limited number of options. Why is this and has anyone found a way around this?
Apple talk more about Displaying Dynamic Dates here: https://developer.apple.com/documentation/widgetkit/keeping-a-widget-up-to-date

You won't like this answer, but as of iOS 14, the answer is there's no way to customize the relative style for Text. The relative style is new in iOS 14, and as always, Apple provide the bare minimum feature.
For now, you have only these choices:
Use other Text.DateStyle, if they work for you
Fallback to DateFormatter (and other formatters) with the tradeoff that widget can only refresh couple of times in a day
Hopefully this won't be the answer with iOS 15 or later.

Related

I want to change the DatePicker Style of UWP

I want to change the DatePicker Style of UWP as shown below.
I want year to come first and month to come second.
I modified the style but it does not work.
What should I do?
Thank you for your reply.
According to this article:
There are many different ways to properly display dates and times. Different regions and cultures use different conventions for the order of day and month in the date, for the separation of hours and minutes in the time, and even for what punctuation is used as a separator.
If you use date and time picker controls, these will automatically use the date and time formats for the user's preferred language and region. So the order is defined by the user's preferred language and region that you should not be able to change them by the style of DatePicker.
The first image you showed above seems like preferred language is en-US and home region is US. For scenarios where you provide different functionality based on the user's language, region, or cultural preferences, Windows gives you a way to access those preferences, through Windows.System.UserProfile.GlobalizationPreferences. And the second image seems like preferred language is Chinese. The preferred language can be override by property PrimaryLanguageOverride. Pay attention that the PrimaryLanguageOverride property should only be set to languages that are available for the user.
So if you change the prefer language to Chinese the DataPicker may be shown in order year-mouth-day. Also formats need be changed as the second image show. Code as follows:
<DatePicker BorderThickness="0" FontFamily="Arial Black" FontSize="15" FontWeight="Bold" MinWidth="190" DayFormat="{}{day.integer(2)}" MonthFormat="month.numeric" YearFormat="{}{year.full(4)}" />
Code behind
ApplicationLanguages.PrimaryLanguageOverride = "zh-Hans-CN";
And the result
To respect the user's Language and Cultural Preferences, this may not be recommended to change.

Custom DatePicker with just two components

I want to to use custom datePicker in my project. In Mode date it shows Month,Day and Year, in my case I don't need Year, I just want to display Month and day.
The API does not provide a way to do this. If you want to be able to, please file a report requesting this ability, and it'll hopefully get included in a future release of iOS.
In the meantime, you can make a pretty convincing replica yourself using a UIPickerView.
Im sorry but following the reference of the PickerView
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIDatePicker_Class/Reference/UIDatePicker.html#//apple_ref/doc/c_ref/UIDatePickerMode
It says that is not possible to do that, so your only option is to implemente yourself the delegate and the datasource, and create the pickerview with the data you need.

Iphone Calendar without marking etc just basic calendar

Could someone possibly show me how to do a basic calendar display that gets the date from date selected in a calendar? The Kal examples and code does way more than I need and is not set for the type of app im making. All I really need is a calendar with the dates, and then from there something to retrieve the date so i can pass it to my other functions. I feel like the UIDatePicker is trashy looking and would like the calendar view if its possible.
Hii Casey,
For simplest / Easy Calender Integration - use Tapku Library
https://github.com/devinross/tapkulibrary
Its simple than compared to Kal.
Tapku Calendar is a solid calendar implementation, I've used it in past iPhone projects. You can check out a blog post I wrote about it earlier this year here: http://developinginthedark.com/posts/iphone-tapku-calendar-markers
I've recently updated it to include example code showing it's integration into a Tab Bar application. Scroll down the bottom of the post to get that Tab Bar application code. If you run into any difficulties, let me know.

GWT Time Picker?

Does anyone know if in GWT we have a good TimePicker ?
In fact I want a widget in order to select hour and minute for GWT.
Thanks
AFAIK there's no such a widget. Also "a good TimePicker" is a bit suggestive. I've been looking for such a widget for a long time and I found some javascript examples that were completely awful, but some people is using.
Finally I decided to do my own, based in a TextBox with value control.
The source code is available, you can find more info here and on github I hope you like it.
I have seen some TimePicker that are simple ComboBoxes.
I know this question was asked a while ago, but I came across it during my search for a GWT time picker and I decided to write my own.
It supports many different input formats (4p => 4:00pm, 745 => 7:45am, etc) and has a drop-down menu with times at fixed intervals.
On iOS, it automatically uses an HTML5 input type="time"
Blog article describing the implementation
Demo of the UTCTimeBox
Demo of the UTCDateBox and UTCTimeBox being used together
Download at Google Code
I created gwt-timepicker which is using the concept of jquery timepicker. It does exactly what you need (hour/minute). Take a look: http://code.google.com/p/gwt-timepicker/
check this post: http://www.summa-tech.com/blog/2011/03/21/gwt-timepicker/
GWT Bootstrap GWT widget library has a nice date+time widget, along with many other solid widgets.
http://gwtbootstrap.github.com/#component:datetimepicker
Edit: Looks like there is newer version available for bootstrap 3.
The gwt incubator has an alright time picker
The code would be something like the example given:
// A TimePicker with no "AM/PM" and no "seconds" field and using 24H formatting for "hours" field
TimePicker timePicker = new TimePicker(new Date(), null, DateTimeFormat.getFormat("HH"), DateTimeFormat.getFormat("mm"), null);
I wrote a Time Picker recently. I wrote it in a hurry, so it's not the best out there, but it works fine.
It attempts to create a HTML5 <input type="time"/> and if it's not supported by the browser, it parses manually. I have tested it on Chrome and Firefox on PC, and iOS.
Accepted formats are:
12:59 AM
5 - assumed to be 5 AM
5p - 5:00 PM
13 - 1 PM
345 - 3:45 AM
1534 - 3:34 PM
111p - 1:11 PM
it implements HasValue<Long> to return the picked time as milliseconds. It also has a method to return the time combined with a given Date object.
Here's the source: https://github.com/srilankanchurro/gwt-stuff/blob/master/gwt-stuff/src/com/sathkumara/client/TimePicker.java
If you have modifications to contribute to this class, please feel free to send me a request on github.
DatePicker and DateBox
DatePicker datePicker = new DatePicker();
DateBox dateBox = new DateBox();
Here is GWT DatePicker example
and you can format the datetime to your needs with DateTimeFormat and here is example
GXT has a TimeField widget Example Good or not it's your choice :)
Maybe you can give an eye to DateTimePicker
https://github.com/ghuntley/Ext.ux.touch.DateTimePicker

Remove the "Today" entry from UIDatePicker

When using a UIDatePicker in iOS SDK, there is always an entry "Today" at the current date.
That's useful in most cases, but where I need it, it's rather confusing.
Is there a way to:
a) disable the "today"-entry (use regular date instead), and have all entries look the same
or even better
b) disable the "today"-entry (use regular date instead), and color the next day in blue
Further more, the application is for private use only, it's not going to get distributed on the AppStore, which means I could use private APIs (I still would rather avoid them) and I don't need it to be backwards compatible. iOS 4 is fine.
I had a similar problem with the UIDatePicker not matching my requirements exactly (in my case I needed a datepicker without a year wheel). Having a look at the UIDatePicker reference, it doesn't look like you can disable the today entry, so you might be forced to do what I did.
I used a UIPickerView and re-implemented the date selection functionality I needed with that. There are a few things you will need to do to implement your custom date picker:
Implement a UIPickerViewDataSource to set up row titles, dimensions and row counts.
Implement a UIPickerViewDelegate to handle events from your custom picker.
Make sure you update your day wheel when the month wheel changes so you get appropriate days for each month. UIDatePicker does this pretty seamlessly. With limited time, I just reload the picker when the month changes so the day counts match up.