new Date( dateString )は、Dateオブジェクトのコンストラクタのひとつで、引数「dateString」に指定した日時のDateオブジェクトを生成する。
構文
new Date( dateString )
引数
- dateString
- Dateオブジェクトの日時を文字列で指定する。
Dateオブジェクト生成例
「2013年4月23日13時25分30秒」のDateオブジェクトを生成。
var $dateObject = new Date( "2013-04-23T13:25:30" );
var $dateObject = new Date( "04/23/2013 1:25:30 pm" );
var $dateObject = new Date( "2013 Apr 23 1:25:30 pm" );
var $dateObject = new Date( "04/23/2013 1:25:30 pm" );
var $dateObject = new Date( "2013 Apr 23 1:25:30 pm" );
サンプル
<script type="text/javascript">
var $dateObject = new Date( "2013" );
document.write( 'new Date( "2013" ): ' + $dateObject + '<br />' );
var $dateObject = new Date( "2013-04" );
document.write( 'new Date( "2013-04" ): ' + $dateObject + '<br />' );
var $dateObject = new Date( "2013-04-23" );
document.write( 'new Date( "2013-04-23" ): ' + $dateObject + '<br />' );
var $dateObject = new Date( "2013-04-23T13:25:30" );
document.write( 'new Date( "2013-04-23T13:25:30" ): ' + $dateObject + '<br />' );
var $dateObject = new Date( "04/23/2013" );
document.write( 'new Date( "04/23/2013" ): ' + $dateObject + '<br />' );
var $dateObject = new Date( "04/23/2013 1:25:30 pm" );
document.write( 'new Date( "04/23/2013 1:25:30 pm" ): ' + $dateObject + '<br />' );
var $dateObject = new Date( "2013 Apr 23" );
document.write( 'new Date( "2013 Apr 23" ): ' + $dateObject + '<br />' );
var $dateObject = new Date( "2013 Apr 23 1:25:30 pm" );
document.write( 'new Date( "2013 Apr 23 1:25:30 pm" ): ' + $dateObject + '<br />' );
</script>
var $dateObject = new Date( "2013" );
document.write( 'new Date( "2013" ): ' + $dateObject + '<br />' );
var $dateObject = new Date( "2013-04" );
document.write( 'new Date( "2013-04" ): ' + $dateObject + '<br />' );
var $dateObject = new Date( "2013-04-23" );
document.write( 'new Date( "2013-04-23" ): ' + $dateObject + '<br />' );
var $dateObject = new Date( "2013-04-23T13:25:30" );
document.write( 'new Date( "2013-04-23T13:25:30" ): ' + $dateObject + '<br />' );
var $dateObject = new Date( "04/23/2013" );
document.write( 'new Date( "04/23/2013" ): ' + $dateObject + '<br />' );
var $dateObject = new Date( "04/23/2013 1:25:30 pm" );
document.write( 'new Date( "04/23/2013 1:25:30 pm" ): ' + $dateObject + '<br />' );
var $dateObject = new Date( "2013 Apr 23" );
document.write( 'new Date( "2013 Apr 23" ): ' + $dateObject + '<br />' );
var $dateObject = new Date( "2013 Apr 23 1:25:30 pm" );
document.write( 'new Date( "2013 Apr 23 1:25:30 pm" ): ' + $dateObject + '<br />' );
</script>
↓↓↓出力結果↓↓↓