JavaScript DHTML/Dojo toolkit/Date
Содержание
Add month to date
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/"
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
</head>
<body>
<script language="JavaScript" type="text/javascript">
dojo.require("dojo.date");
var d1 = new Date();
alert(d1);
d1 = dojo.date.add(d1, "month", 2);
alert(d1);
</script>
</body>
</html>
Compare two dates
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/"
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
</head>
<body>
<script language="JavaScript" type="text/javascript">
dojo.require("dojo.date");
var d1 = new Date();
alert(d1);
d1 = dojo.date.add(d1, "month", 2);
alert(d1);
var d2 = new Date();
document.write(dojo.date.rupare(d1, d2));
alert(dojo.date.difference(d1, d2, "week"));
</script>
</body>
</html>
Convert date to ISO format string
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/"
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
</head>
<body>
<script language="JavaScript" type="text/javascript">
dojo.require("dojo.date.stamp");
alert(dojo.date.stamp.toISOString(new Date()));
</script>
</body>
</html>
Create dojo.Date
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/"
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
</head>
<body>
<script language="JavaScript" type="text/javascript">
dojo.require("dojo.date");
var d1 = new Date();
alert(d1);
</script>
</body>
</html>
Create dojo date object
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/"
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
</head>
<body>
<script language="JavaScript" type="text/javascript">
dojo.require("dojo.date");
var d1 = new Date();
alert(d1);
d1 = dojo.date.add(d1, "month", 2);
alert(d1);
</script>
</body>
</html>
Get date difference
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/"
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
</head>
<body>
<script language="JavaScript" type="text/javascript">
dojo.require("dojo.date");
var d1 = new Date();
alert(d1);
d1 = dojo.date.add(d1, "month", 2);
alert(d1);
var d2 = new Date();
document.write(dojo.date.rupare(d1, d2));
alert(dojo.date.difference(d1, d2, "week"));
</script>
</body>
</html>
Get day in a month
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/"
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
</head>
<body>
<script language="JavaScript" type="text/javascript">
dojo.require("dojo.date");
var d = new Date();
alert(dojo.date.getDaysInMonth(d));
</script>
</body>
</html>
Get time zone
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/"
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
</head>
<body>
<script language="JavaScript" type="text/javascript">
dojo.require("dojo.date");
var d = new Date();
alert(dojo.date.getTimezoneName(d));
</script>
</body>
</html>
Is leap year
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/"
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
</head>
<body>
<script language="JavaScript" type="text/javascript">
dojo.require("dojo.date");
var d = new Date();
alert(dojo.date.isLeapYear(d));
</script>
</body>
</html>
Parse ISO Date format string
<html>
<head>
<script type="text/javascript">
var djConfig = {
baseScriptUri : "js/dojo/"
};
</script>
<script type="text/javascript" src="js/dojo/dojo/dojo.js"></script>
</head>
<body>
<script language="JavaScript" type="text/javascript">
dojo.require("dojo.date.stamp");
alert(dojo.date.stamp.fromISOString("2009-06-30T08:08:00-08:00"));
</script>
</body>
</html>