473,382 Members | 1,657 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Reformatting the javascript locale date

Hi all,

The format of the date given by the javascript date.toLocaleDateString() is not what I want, is it possible to reformat it?

Currently, my locale is under US. The date.toLocaleDateString() showing Wednesday, July 18, 2007, will it be possible to format it to July 18, 2007 (MM dd, yyyy)?


Thanks
Jul 18 '07 #1
5 7639
pbmods
5,821 Expert 4TB
Heya, neo2020. Welcome to TSDN!

You can't change the output of Date::toLocaleString(). But you can access individual elements of the date.
Jul 18 '07 #2
Heya, neo2020. Welcome to TSDN!

You can't change the output of Date::toLocaleString(). But you can access individual elements of the date.
Hi pbmods, thanks for ur quick reply.

Hmm, so that's mean in order to achieve what I want to do, i have to retrieve user browser locale info, and customize the date format accordingly?

Thanks
Jul 18 '07 #3
acoder
16,027 Expert Mod 8TB
Hi pbmods, thanks for ur quick reply.

Hmm, so that's mean in order to achieve what I want to do, i have to retrieve user browser locale info, and customize the date format accordingly?

Thanks
If you want to output the date in a certain format, why not use the Date methods to get the date, month and year and make your own string version (for month, you can create an array of the month names), e.g.
Expand|Select|Wrap|Line Numbers
  1. var today = new Date();
  2. var d = today.getDate();
  3. var m = today.getMonth();
  4. var y = today.getFullYear();
  5. var months = new Array("January", "February",...);
  6. datestr = months[m] + " " + d + ", " + y;
Jul 18 '07 #4
If you want to output the date in a certain format, why not use the Date methods to get the date, month and year and make your own string version (for month, you can create an array of the month names), e.g.
Expand|Select|Wrap|Line Numbers
  1. var today = new Date();
  2. var d = today.getDate();
  3. var m = today.getMonth();
  4. var y = today.getFullYear();
  5. var months = new Array("January", "February",...);
  6. datestr = months[m] + " " + d + ", " + y;
Hi acoder, thanks for ur reply.

The user of the application may from different locale. eg some from US, some from UK. The default output date string for US locale is too long, and I want to reduce the length to only include MM dd yyyy. From my previous post, what I am trying to say is I only can base on the user locale retrieve via javascript , and provide the custom format of the date string?
Jul 18 '07 #5
acoder
16,027 Expert Mod 8TB
Hi acoder, thanks for ur reply.

The user of the application may from different locale. eg some from US, some from UK. The default output date string for US locale is too long, and I want to reduce the length to only include MM dd yyyy. From my previous post, what I am trying to say is I only can base on the user locale retrieve via javascript , and provide the custom format of the date string?
Oh, in that case, parse the string. Look for the first comma and get the string after that.
Jul 18 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.