開発環境
- OS X Lion - Apple(OS)
- Emacs、BBEdit - Bare Bones Software, Inc. (Text Editor)
- Ruby (プログラミング言語)
『初めてのプログラミング 第2版』(Chris Pine 著、長尾 高弘 訳、オライリー・ジャパン、2010年、ISBN978-4-87311-469-9)の 12章(新しいクラスのオブジェクト), 12.1(Timeクラス)、12.2(練習問題)、10億秒、を解いてみる。
その他参考書籍
- 『プログラミング言語 Ruby』David Flanagan, まつもと ゆきひろ 著 、卜部 昌平 監訳、長尾 高弘 訳、オライリー・ジャパン、2009年、ISBN978-4-87311-394-4)
- Rubyクックブック ―エキスパートのための応用レシピ集
10億秒
コード(BBEdit)
sample.rb
#!/usr/bin/env ruby2.0 #-*- coding: utf-8 -*- birth = Time.utc(2000, 1, 2, 3, 4, 5) puts "誕生日: #{birth}" puts "10億秒後: #{birth + 10 ** 9}"
入出力結果(Terminal)
$ ./sample.rb 誕生日: 2000-01-02 03:04:05 UTC 10億秒後: 2031-09-10 04:50:45 UTC $
ちなみにpython3.4の場合。
コード(BBEdit)
sample.py
#!/usr/bin/env python #-*- coding: utf-8 -*- import datetime birth = datetime.datetime(2000, 1, 2, 3, 4, 5) now = datetime.datetime.fromtimestamp(birth.timestamp() + 10 ** 9) print('誕生日: {0}'.format(birth.ctime())) print('10億秒後: {0}'.format(now.ctime()))
入出力結果(Terminal)
$ ./sample.py 誕生日: Sun Jan 2 03:04:05 2000 10億秒後: Wed Sep 10 04:50:45 2031 $
0 コメント:
コメントを投稿