開発環境
- OS X Lion - Apple(OS)
- BBEdit - Bare Bones Software, Inc.(Text Editor)
- Script言語:Ruby
『初めてのプログラミング 第2版』(Chris Pine 著、長尾 高弘 訳、オライリー・ジャパン、2010年、ISBN978-4-87311-469-9)の 2章(数値), 2.5(練習問題)秒で数えたあなたの年齢 を解いてみる。
その他参考書籍
- 『プログラミング言語 Ruby』David Flanagan, まつもと ゆきひろ 著 、卜部 昌平 監訳、長尾 高弘 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-394-4)
- Rubyクックブック ―エキスパートのための応用レシピ集
秒で数えたあなたの年齢
コード(BBEdit)
sample.rb
#!/usr/bin/env ruby1.9 #-*- coding: utf-8 -*- puts Time.new - Time.local(2000, 1, 2, 3, 4, 5)
入出力結果(Terminal)
$ ./sample.rb 414161116.22228605 $
ちなみにJavaScriptの場合。
コード(BBEdit)
var result = (new Date() - new Date(2000, 1 - 1, 2, 3, 4, 5)) / 1000; $('#pre0').text(result);
pythonの場合。
sample.py
コード(BBEdit)
#!/usr/bin/env python3.3 #-*- coding: utf-8 -*- import datetime print(datetime.datetime.now().timestamp() - datetime.datetime(2000, 1, 2, 3, 4, 5).timestamp())
入出力結果(Terminal)
$ ./sample.py 414161734.253134 $
perlの場合。
sample.pl
コード(BBEdit)
#!/usr/bin/env perl use strict; use warnings; use utf8; use 5.016; binmode STDIN, ":utf8"; binmode STDOUT, ":utf8"; use Time::Local; print timelocal(localtime) - timelocal(5, 4, 3, 2, 1 - 1, 2000 - 1900) , "\n";
入出力結果(Terminal)
$ ./sample.pl 414161990 $
0 コメント:
コメントを投稿