Monday 31 March 2014

Passing date value as a string to JavaScript Date() object

Date() Constructor has following variations

new Date();
new Date(value);
new Date(dateString);
new Date(year, month [, day, hour, minute, second, millisecond]);

Date constructor parameters

Note: Where Date is called as a constructor with more than one argument, if values are greater than their logical range (e.g. 13 is provided as the month value or 70 for the minute value), the adjacent value will be adjusted. E.g.  new Date(2013,13,1) is equivalent to new Date(2014,1,1), both create a date for 2014-02-01 (note that the month is 0-based).
value

Integer value representing the number of milliseconds since 1 January 1970 00:00:00 UTC.

dateString

String value representing a date. The string should be in a format recognized by the Date.parse() method (IETF-compliant RFC 2822 timestamps and also a version of ISO8601). Date.parse()

The parse method takes a date string (such as "Dec 25, 1995") and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC. This function is useful for setting date values based on string values, for example in conjunction with the setTime() method and the Date object.

Date.parse() understands the continental US time-zone abbreviations, but for general use, use a time-zone offset, for example, "Mon, 25 Dec 1995 13:30:00 +0430" (4 hours, 30 minutes east of the Greenwich meridian). If you do not specify a time zone, the local time zone is assumed.

<script>
alert(new Date("March 18, 2014"))
alert(new Date("March 18, 2014 00:00:00 +0430"))
alert(new Date("18 March 2014"))
alert(new Date("2014-03-18"))
</script>

year

Integer value representing the year. Values from 0 to 99 map to the years 1900 to 1999.

month

Integer value representing the month, beginning with 0 for January to 11 for December.

day

Integer value representing the day of the month.

More info

Date Object

Date.parse

JavaScript Dates

Wednesday 26 March 2014

CSS3 word-break and word-wrap properties

word-break

Normally, line breaks in text can only occur in certain spaces, like when there is literally a space or a hyphen. When you set word-break to break-all, line breaks can occur between any character. Resulting in, for example:

Perform
ance

(if that word wouldn't quite fit into its parent container width)

Syntax
  word-break: normal | break-all | keep-all;
Example
p {
  word-break: break-all;
}

It's often used in places with user generated content so that long strings don't risk breaking layout. One very common example is a long copy and pasted URL. If that URL has no hyphens, it can extend beyond the parent box and look bad or worse, cause layout problems.

Read about word-break on w3schools.com

Read about word-break on css-tricks.com

word-wrap

Allow long words to be able to break and wrap onto the next line:

Syntax
word-wrap: normal|break-word|initial|inherit;
p.test {word-wrap:break-word;}

Read about word-wrap on w3schools.com

Friday 21 March 2014

What is the difference between DIV and SPAN?

div is a block element, span is inline. This means that to use them semantically, divs should be used to wrap sections of a document, while spans should be used to wrap small portions of text, images, etc.