javascript client date format - javascript

I had a problem on extjs date. Seem by default it using computer date to create a date.
I don't check up my pc and post the date.Then i found it based on American
M/d/yyyy.
After i change the system regional setting date to d-m-Y.Everthing work fine.
So anybody know how extjs get client date format ?
e.g 'YYYY-mm-dd' or 'M/d/yyyy' .
Since i need to parse the format from extjs code to php to mysql date format.
I try to find stackoverflow and site but seem not found out,

You can convert date to String when transfer it so that you can set the date format by yourself.

Actually the default format used is 'm/d/y', and you can change the format self, and I don't think so the ext can get the client date format and change the format consistently.

dont mind your regional setting
you have two options
in your server you convert to string and change format
yourDate.ToString("MMM dd, yyyy")
see here or here for standard and custom format
or in your extjs code you use
renderer: Ext.util.Format.dateRenderer('d-M-Y'),
see here for available format strings.

Related

Accessing the Locale Date format with in program automatically

Is there a function which will help us to write the date using the Locale settings in Javascript.For example in my machine as per the Locale settings the format is M/D/YYYY so in my program the date should be printed in this format. If i change my the Locale settings in computer format to YYYY-MM-DD then my program should automatically print in this format without hardcoding the format. This is the expected behavior of my program. As some of the suggestions given on using toLocaleDateString method, On using toLocaleDateString it always returns in M/D/YYYY format only even then the computer Date format is changed to YYYY-MM-DD. I searched in internet i don't find any proper answer please guide me to do this. Any help is appreciated.

Generate WCF JSON format Date with moment.js or another javascript library

I am consuming a WCF Service in Javascript and need to play around with dates.
I was looking around for some nice DateTime handlers for the format the DataContractJsonSerializer generates { "date": "/Date(1260597600000-0600)/" } and found moment.js. moment.js is really excellent to consume this date format, handles the format including the timezone.
What I need now is generate the WCF date format from a Javascript or moment Date to send dates with timezones in the request on my POST method and looking in the documentation of moment.js couldn't find anything that has the output I need.
Any idea how to achieve this with moment.js or any other js library?
Thanks.
With moment.js:
yourMomentObject.format("/[Date](xZZ)/")
Example:
Without moment, you can write your own function that takes uses the Date object's .getTime() function, and .getTimezoneOffset() functions. However, the offset has to be negated, then formatted properly before being added to the string.

Where does the date time format coming when use date toLocaleString?

I'm facing some date time formatting related issue.
I'm confused about how a date object's output string is formatted. I did some testing in debug, when I call the toLocalString, the output is not following locale settingin the OS .
Below is the output of the method:
"1/12/2015, 8:12:12 PM"
But what I did in the os locale setting is
Why is toLocaleString formatting the date this way? where does those format coming from?
Where to change the format setting browser is using?
Why is toLocaleString formatting the date this way?
toLocaleString() doesn't watch for user's locale formatting settings before returning the string.
Where does those format coming from?
The format is based on the conventions of user's time zone for representing date and time. So, format is machine independent.
Where to change the format setting browser is using?
As stated the format is implementation dependent. It won't help you anything. And I think browsers don't provide such functionality.
For reference I have included it's documentation below.
The Documentation of Date.toLocaleString() as mentioned in Javascript: The Definitive Guide says:
Returns
A string representation of the date and time specified by date. The date and time are repre- sented in the local time zone and formatted using locally appropriate conventions.
Usage
toLocaleString() converts a date to a string, using the local time zone. This method also uses local conventions for date and time formatting, so the format may vary from platform to platform and from country to country. toLocaleString() returns a string formatted in what is likely the user’s preferred date and time format.

Validate a date in Nodejs with MomentJs

I want to validate a date in a NodeJS application.
I tried the MomentsJs library, but it seems that the isValid() function ignored all alpha characters, it's too tolerant for me (When I specify the dateformat as YYYY-MM-DD, I expect that the date is a 10-characters-string.):
moment("One,2 and 011, 12-10", "YYYY-MM-DD").isValid() // returns true instead of false
moment("Seppl"); // parsing seems to work with all values?
Is there any way to check dates more strictly?
How can I check if parsing a date fails? (It returns -62167222800000 when printing wrong dates it).
Is there any other better Javascript Data lib that work with different date formats and support date manipulations like MomentJs?
Moment.js library doesnt provide any method validate the date with given format.
moment("<>", dateFormat) will just check the given date but not with given format.
Following lines from momentjs.com
Note: It is not intended to be used to validate that the input string matches the format string. Because the strictness of format matching can vary depending on the application and business requirements, this sort of validation is not included in Moment.js.
http://momentjs.com/docs/#/parsing/is-valid/

Free-Form Date Picker - like RTM

I'm looking for a way to have a textbox that allows users to type in a date in any format and turns around and formats that date in a 'mm/dd/yyyy' format. So the user could type in "Today" and it would turn the date as 02/24/2009 or they could type in Wednesday Feb 24 and formatting would automatically pick up. Remember the Milk does this (but I believe server side). This is asp.net so I could do via ajax web service call but I would prefer to do this via Javascript. I'm looking for a general technique or existing library to help with this.
Check out http://www.datejs.com/

Categories