473,320 Members | 1,876 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,320 software developers and data experts.

Date without time for toLocaleString

When calling the function toLocaleString(), javascritp date object returns
yyyy/mm/dd HH:MM:SS depending on the locale settings. Is it possible to
just display date as yyyy/mm/dd without the time ?

SK
Nov 27 '05 #1
4 7307
RandyTh wrote:
When calling the function toLocaleString(), javascritp date object returns
yyyy/mm/dd HH:MM:SS depending on the locale settings. Is it possible to
just display date as yyyy/mm/dd without the time ?


Sure, you just need to change your locale :)

Seriously, try this quickhack:

var
d = new Date(...),
month = d.getMonth() + 1,
day = d.getDate();

if (!Date.prototype.getFullYear)
{
Date.prototype.getFullYear = function()
{
var y = this.getYear();
return (y < 1900 ? y + 1900 : y);
}
}

[d.getFullYear(),
(m < 10 ? "0" + month : month),
(d < 10 ? "0" + day : day)].join("/")

However, I strongly recommend to stick to the ISO date format
(YYYY-MM-DD) to avoid any ambiguities regarding `yyyy/mm/dd'.
HTH

PointedEars
Nov 27 '05 #2
Thomas 'PointedEars' Lahn wrote:
[d.getFullYear(),
(m < 10 ? "0" + month : month),
(d < 10 ? "0" + day : day)].join("/")

^
Sorry, should have been

[d.getFullYear(),
(m < 10 ? "0" + month : month),
(day < 10 ? "0" + day : day)].join("/")
PointedEars
Nov 27 '05 #3
Thomas 'PointedEars' Lahn wrote:
[d.getFullYear(),
(m < 10 ? "0" + month : month),
(d < 10 ? "0" + day : day)].join("/")

^
Sorry, should have been

[d.getFullYear(),
(month < 10 ? "0" + month : month),
(day < 10 ? "0" + day : day)].join("/")
PointedEars
Nov 27 '05 #4
JRS: In article <69****************@PointedEars.de>, dated Sun, 27 Nov
2005 12:55:10, seen in news:comp.lang.javascript, Thomas 'PointedEars'
Lahn <Po*********@web.de> posted :
if (!Date.prototype.getFullYear)
{
Date.prototype.getFullYear = function()
{
var y = this.getYear();
return (y < 1900 ? y + 1900 : y);
}
}

AIUI, that is not correct for at least one browser, which implements
getYear() to give (at least around 2000) what getFullYear()%100 gives.

However, one can write a function getFY - not much longer than the
above - that is safe on any browser for which getYear()%100 is
always right. Read the newsgroup FAQ; see below.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Nov 28 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Vince C. | last post by:
Hi all. I'm trying to set a cookie expiry date but my script is JS (JavaScript). I've tried Response.Cookies("Test").Expires = Date(); Response.Cookies("Test").Expires =...
1
by: Raskolnikow | last post by:
Hi! I have some beginner questions about C++, so please be gentle if the things I ask are trivial. What I want to do is a program that - changes the current (system) date, - calls an...
2
by: FN | last post by:
I'm new to javascript and internet research is turning up weird things. I just want to add 5 seconds to a date value. this = new date() // I believe this sets the time, too, right? //now how...
2
by: Trev | last post by:
Is there a way to format a date to the current user's country settings? The date I post from the Date() function (Mozilla/JavaScript) is incomprehensible by the back-end application (ASP/VBScript).
3
by: John Kenickney | last post by:
I use ASP/Javascript. I pull a date from a recordset field like this. var theDate = new Date() theDate = rs.Fields.Item("date").value Now I want to apply the method toLocaleString(). There are...
13
by: maflatoun | last post by:
Hi, I have the following function to convert UTC time to Local time. It works perfect for GMT- (Minus) time zones however it provides incorrect results for GMT+(Plus) time zones? // Format to...
5
by: Beeker | last post by:
Hi Guys We shipped our software out to a customer that contains a piece of javascript that looks like this: var date = new Date(); var time = date.toLocaleTimeString(); ...Which works on...
13
by: ahjiang | last post by:
Hi all, Need some help here. How do i create a javascript date object with the format (yyyy:mm:dd hh:mm:ss) do i need to parse it to achieve that? appreciate any inputs
14
by: shapper | last post by:
Hello, Is there any function to convert a Date/Time from UTC to the user client zone and back from user client zone to UTC? I want to store Date/Time in UTC in the database but display it in...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.