Use the ISO8601 date format YYYY-MM-DD THH:mm:ssZ and there are datetime standardisation libraries for javascript, along with the UTC methods to avoid timezone issues. The biggest issue with Date values in JavaScript is that there is a lot of undefined behaviour in the Date objects. For anyone who needs a consistent Date api I would suggest using a fixed implementation that overrides the default Date object, allowing for consistent behaviour across all browsers, but do be careful if you have other libraries which are dependent on this.
I have used https://github.com/csnover/js-iso8601/ in the past without issues
http://www.w3.org/TR/NOTE-datetime
Does Javascript/EcmaScript3 support ISO8601 date parsing?
Update
As requested, to actually achieve what you want if you don't want to use a standards compliant date format, this is how you might go about implementing the object you want
var UserDate = (function () {
function UserDate(dateString) {
var dateArray= dateString.split('.'), i;
if (dateArray.length !== 5) {
// Handle this however you want, throw exception,
// bad date type etc
}
// No need to trim, parseInt doesn't care about
// leading or trailing whitespace
for (i = 0; i < dateArray.length; i += 1) {
dateArray[i] = parseInt(dateArray[i], 10);
}
// Check that the date array is well formed here if you want,
// check for NaN and value range
// ...
this._dateArray = dateArray;
}
// Creates a date string from the internal date array
UserDate.prototype.getDate = function () {
var dateString = "", i;
for (i = 0; i < this._dateArray.length; i += 1) {
dateString += this._dateArray[i];
if (i < this._dateArray.length - 1) {
dateString += ".";
}
}
return dateString;
};
// Returns the day value from the internal date array
UserDate.prototype.getDay = function () {
return this._dateArray[0];
};
// Returns the month from the internal date array
UserDate.prototype.getMonth = function () {
return this._dateArray[1];
};
// Returns the year from the internal data array
UserDate.prototype.getYear = function() {
return this._dateArray[2];
};
// Returns the hour from the internal date array
UserDate.prototype.getHour = function() {
return this._dateArray[3];
};
// Returns the minute from the internal date array
UserDate.prototype.getMinute = function() {
return this._dateArray[4];
};
// more prototypes here
return UserDate;
}());
With my tests in the console:
> var someDate = new UserDate("3.11.2012.4.3");
> someDate.getDate()
"3.11.2012.4.3"
> someDate.getYear()
2012
> someDate.getMonth()
11
> someDate.getDay()
3
> someDate.getHour()
4
> someDate.getMinut()
3
Seriously don't consider editing String.prototype to give you this functionality. It's very bad practice to extend the native prototypes in JavaScript unless you are really sure what you are doing. It certainly doesn't make any sense to be adding such bespoke functionality to a general purpose string object. If you need global access to this UserDate object then make it a global object as it would be in this example. The danger is that you don't know what third party libraries are doing to the prototype.
http://perfectionkills.com/extending-built-in-native-objects-evil-or-not/
Might be worth a read if you're interested in the arguments in general. If you really really really want to extend the string prototype then you could do something like
String.prototype.getDay = function () {
return this.split('.')[0];
}
But this will make me a sad chicken.