How do I retrieve the locale-specific date format string in Flex / ActionScript 3? - flex3

How do I retrieve the locale-specific date format string in Flex / ActionScript 3? I am unable to find a method to return the actual format string (that which specifies the date format) based on the current locale. I am asking this question because I was hoping to find a way to convert a String to a Date based on the current SHORT date format for the locale. Java allows one to call:
DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT, locale)
to retrieve an instance of DateFormat that formats according to the SHORT format based on the locale.
Does similar functionality exist in Adobe Flex (ActionScript 3) 3? If not, is there a reliable third party library that exists for this?

I'm just found this package that do the job. Here describe the class DateTimeFormatter:
var formatter:DateTimeFormatter = new DateTimeFormatter(LocaleID.DEFAULT, DateTimeStyle.LONG, DateTimeStyle.SHORT);
var result:String = formatter.format(date);
Just cool.

Extending Gojan's answer:
private function cc(event:FlexEvent):void {
var formatter:DateTimeFormatter = new DateTimeFormatter(LocaleID.DEFAULT, DateTimeStyle.SHORT, DateTimeStyle.NONE);
//now if publishDate is a mx:DateField, the formatString of spark and mx components are slightly different.
//So, we replace all d with D and y with Y
publishDate.formatString=replaceAll(formatter.getDateTimePattern(), ["d", "y"], ["D", "Y"]);
}
private function replaceAll(text:String, searchArray:Array, replArray:Array):String {
for (var i:int=0; i<searchArray.length; i++) {
var s:String=searchArray[i];
var d:String=replArray[i];
text=text.split(s).join(d);
}
return text;
}

Yeah I have to say Java is better with dates - you set the locale and automatically your dates are outputted correctly! I can't seem to find such a facility in Flex.
In order to output your dates correctly for each locale I think you have to do what is written in this article: http://livedocs.adobe.com/flex/3/html/help.html?content=l10n_1.html. Maybe you should do this, and in the same class just make these strings which you've pulled from the locale file available to the rest of your app, then you'll be able to operate on them.
Otherwise perhaps this guy's library will help you? I'm not sure.
http://flexoop.com/2008/12/flex-date-utils-date-and-time-format-part-ii/

Related

How to format date for BigCommerce blog post

I keep getting errors while trying to create blog posts via API calls to BigCommerce, due to the published_date_iso8601 field.
This field expects the date string in this kind of format "5/18/2018 1:26:42 PM", as per the docs here: https://developer.bigcommerce.com/api-reference/1b41aac9b9f54-create-a-blog-post
My data has the dates in this format: "2022-05-12T13:09:23-07:00"
I am using Javascript, and I have tried multiple ways to transform the format, but no success so far.
I have tried built-in JS Date methods
const originalDate = "2022-05-12T13:09:23-07:00"
const newDate = new Date(originalDate).toISOString()
I have tried using Moment
const originalDate = "2022-05-12T13:09:23-07:00"
const newDate = moment(
originalDate
).format('DD/MM/YYYY HH:mm:ss A')
And multiple variations of formatting besides those 2 examples, but I still can't get the post to go through. The error is only a 400 code with no message.
Anyone know how to format this?
Try using the published_date field and new Date('2022-05-12T13:09:23-07:00').toUTCString()?
Hopefully, this should work for you.
A

Expo Calendar - Using the recurrenceRule for createEventAsync()

I'm struggling with some of the formatting for parameters inside the recurrenceRule when trying to create a new event with Expo Calendar. I can't seem to find any robust recurrence examples in the docs or anywhere else for that matter. One specific thing I'm struggling is daysOfTheWeek, where I'm trying to pass multiple days but I'm not even sure if you can.
Does anyone have a good working example of the recurrenceRule in action?
After struggling with this myself I found that if you look up types in your Calendar.d.ts file it should give you the required structure of the recurrenceRule.
export declare type RecurrenceRule = {
frequency: string
interval?: number // #default 1
endDate?: string | Date
occurrence?: number
daysOfTheWeek?: DaysOfTheWeek[]
daysOfTheMonth?: number[]
monthsOfTheYear?: MonthOfTheYear[]
weeksOfTheYear?: number[]
daysOfTheYear?: number[]
setPositions?: number[]
};
So if your use case is like mine and you just want the event to occur only once something like this will work: recurrenceRule: {frequency: 'DAILY', occurrence: 1} I think. Expo-documentation says recurrence rule can be set to null, but this throws an error. Hope this helps!

Pentaho kettle convert date to unix

I'm trying to pacha a string format dated "2019-05-14 13:30:00" to a UNIX format.
In javascript I got it but in the javascript kettle module I am not able to return the numeric value 1557833442
the line of code is this:
const tests = (new Date ("2019-05-14 13:30:00"). getTime () / 1000);
It looks like the Date() constructor doesn't like the format you are using.
If you want the current date, use a Get System Info, it has a number of useful date options.
If you are converting an incoming field, use the Select Values step to change the metadata, using the format string that matches your string field's format.

Telligent 10 - Velocity Template - get current datetime

Using Telligent 10 platform and their native Velocity Template Language, how can we simply get the current datetime?
Per the many examples I've seen here on SO these first two require the $date var previously defined and those examples all define the date statically not by getting the current system datetime so the following do not work:
#set ($today = $date.getCurrentDate())
<span>$today</span>
#set ($today = $date.getDate())
<span>$today</span>
Per this Telligent Community thread I read that Telligent uses .NET DateTime (of which I'm very familiar) but ... these don't work either in Widget Studio:
#set ($today = DateTime.Now)
<span>$today</span>
#set ($today = new DateTime)
<span>$today.Now</span>
Found it. I overlooked the properties (literally the first section) outlined for the $core_v2_utility.
We can get the current date by using the following:
$core_v2_utility.CurrentDate

Getting view options in Microsoft Project using VBA

If I want to change the current date format to 20, for example, I can use the command
OptionsViewEx DateFormat:=20
but how can I get the current date format (or any other view option for that matter)?
DefaultDateFormat should be the function to use.
oldvalue = Application.DefaultDateFormat
Application.DefaultDateFormat = 20 ' or = pjDate_mm_dd_yyyy
This gets or sets the default date format. (technet)
This gives the complete list of format types.
If you use Date function get a date in current format, but if you need change use format(Date,"yyyy-mmmm-dd") for example.