Mihail Stoynov's blog!
Surrender your ego
Monday, August 06, 2007
JavaScript and its traits
This is a story about my trying to print a date using javascript.
I was working on an ajax component and had to display a date in the following
format:
YYYY.MM.DD
.
First of all js (javascript) doesn't supply a formating method. At least
I didn't find one.
Then I tried to get the months using the js method
Date.getMonth()
.
It comes out that the months are in the range 0-11, and not 1-12 as
expected. WTF?
After that I try to print the day, logically using the
Date.getDay()
. Wrong.
The getDay() returns the day of the week (0=Sunday, 6=Saturday). I read
a little more. The correct method is
Date.getDate()
. I expect the range
0-30, again wrong. The range is 1-31. Go figure...
Then I try to print the year. Again a surprise. Years before the year
2000 are returned in a two-digit format. The year 1997 is returned as
97. And the biggest problem there is that the js calendar (a fancy
js thing that we use to choose a date) sees 97 as the year 97
and not 1997. Crazy!
JavaScript sucks. Sucks big time.
How about a good naming convention?
And if you think java is better, look at this:
If you have a
java.util.Calendar
object and want to see the time in
milliseconds since the start of the Era (00:00:00 01.01.1970) you have
to write this:
calendar.getTime().getTime()
\________________/
returns a
Date
\__________________________/
returns a
long
Does this look clean or neat? Would it be clear if I didn't tell you
what it did? For me - not really.
Again, how about a good naming convention.
And don't even get me started on inline conditionals - in java and in
javascript they have different priority. Again: go figure... One has to
put extra brackets just to make sure.
Comments [0]
|
Trackback
OpenID
Please login with either your
OpenID
above, or your details below.
Name
E-mail
(will show your
gravatar
icon)
Home page
Remember Me
Comment (Some html is allowed:
a@href@title, blockquote@cite, strike
) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.
Enter the code shown (prevents robots):
Live Comment Preview
dasBlog theme by
Mads Kristensen
RSS feed
Search
Archives
November, 2008 (15)
October, 2008 (16)
September, 2008 (30)
August, 2008 (15)
July, 2008 (14)
June, 2008 (26)
May, 2008 (6)
April, 2008 (21)
March, 2008 (14)
February, 2008 (28)
November, 2007 (5)
October, 2007 (7)
September, 2007 (1)
August, 2007 (7)
July, 2007 (3)
June, 2007 (1)
Blog Stats
Total Posts: 203
This Year: 179
This Month: 15
This Week: 2
Comments: 74
Categories
Did you know
Java
rulez
Sucks
БГ
Blogroll
Michael Moore (no rss)
Links
BG-JUG
Copyright policy
No rights reserved.
(You are going to
copy stuff anyway :)
If you mention my
name, thank you.
2008, Mihail Stoynov