開発環境
- OS X Lion - Apple(OS)
- BBEdit - Bare Bones Software, Inc.(Text Editor)
- プログラミング言語: 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 ruby2.0 #-*- coding: utf-8 -*- b = Time.gm(2000, 1, 2, 3, 4, 5) puts Time.new - b
入出力結果(Terminal)
$ ./sample.rb 417331058.069864 $
ちなみにJavaScriptの場合。
コード(BBEdit)
var b = new Date(2000, 1 - 1, 2, 3, 4, 5), result = (new Date() - b) / 1000; $('#pre0').text(result);
pythonの場合。
sample.py
コード(BBEdit)
#!/usr/bin/env python3.3 #-*- coding: utf-8 -*- import datetime b = datetime.datetime(2000, 1, 2, 3, 4, 5) print(datetime.datetime.today().timestamp() - b.timestamp())
入出力結果(Terminal)
$ ./sample.py 417363712.799505 $
0 コメント:
コメントを投稿