# Time#to\_s format

**URL:** <https://www.ruby-forum.com/t/time-to-s-format/87702>\
**Category:** Development\
**Created:** [March 5, 2007, 10:45am UTC](https://www.ruby-forum.com/t/time-to-s-format/87702 "2007-03-05T10:45:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![OHARA\_Shigeki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c37758/32.png) [@OHARA\_Shigeki](https://www.ruby-forum.com/u/OHARA_Shigeki)\
**Post date:** [March 5, 2007, 10:45am UTC](https://www.ruby-forum.com/t/time-to-s-format/87702/1 "2007-03-05T10:45:00Z")

</div>

e$BBg86$G$9!#e(B

Ruby 1.8.6 e$B$+$ie(B Time#to\_s e$B$N7A\<0$,e(B  
RFC 2822 e$B=`5r$KJQ99$K$J$k$h$&$J$N$G$9$,!"e(B  
e$B$3$N7A\<0$,4V0c$C$F$$$k$h$&$K;W$$$^$9!#e(B

From: “NARUSE, Yui” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Subject: [ruby-dev:29467] Re: [ruby-cvs:17256] ruby, ruby: \* time.c  
(time\_to\_s): generate RFC822 style date string.  
Message-ID: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Date: Mon, 4 Sep 2006 18:33:50 +0900

> e$B$K$J$C$F$$$^$9$,!"e(B  
> p Time.now, Time.now.utc  
> Mon, Sep 04 2006 18:12:44 +0900  
> Mon, Sep 04 2006 09:12:44 UT  
> e$B$,@5$7$$$+$H!#e(B

RFC 2822 e$B$Ne(B 3.3. Date and Time Specification e$B$K$h$k$H!"e(B

date = day month year

e$B$,@5$7$$$h$&$G$9!#e(B

* * *

OHARA Shigeki (e$BBg86e(B e$B=E\<ye(B) [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![OHARA\_Shigeki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c37758/32.png) [@OHARA\_Shigeki](https://www.ruby-forum.com/u/OHARA_Shigeki)\
**Post date:** [March 5, 2007, 11:28am UTC](https://www.ruby-forum.com/t/time-to-s-format/87702/2 "2007-03-05T11:28:05Z")

</div>

At Mon, 5 Mar 2007 18:44:19 +0900,  
OHARA Shigeki wrote:

> Ruby 1.8.6 ã‹ã‚‰ Time#to\_s ã®å½¢å¼ãŒ  
> RFC 2822 æº–æ‹ ã«å¤‰æ›´ã«ãªã‚‹ã‚ˆã†ãªã®ã§ã™ãŒã€  
> ã“ã®å½¢å¼ãŒé–“é•ã£ã¦ã„ã‚‹ã‚ˆã†ã«æ€ã„ã¾ã™ã€‚  
> (snip)  
> RFC 2822 ã® 3.3. Date and Time Specification ã«ã‚ˆã‚‹ã¨ã€
> 
> date = day month year
> 
> ãŒæ­£ã—ã„ã‚ˆã†ã§ã™ã€‚

ã€€ç¢ºã‹ã«ãã®é€šã‚Šã§ã™ã­ã€‚ä¿®æ­£ã—ã¾ã™ã€‚

% /usr/local/bin/ruby -v -rtime -e ‘Time.rfc2822(Time.now.to\_s)’  
ruby 1.8.6 (2007-03-05 patchlevel 0) [i686-darwin8.8.3]  
/usr/local/lib/ruby/1.8/time.rb:296:in `rfc2822’: not RFC 2822 compliant  
date: “Mon, Mar 05 2007 19:25:08 +0900” (ArgumentError)  
from -e:1

ã€€ã¡ã‚‡ã£ã¨æƒ…ã‘ãªã„â€¦ã€‚

–  
/  
/\_\_ \_\_ [Akinori.org](http://Akinori.org) / [MUSHA.org](http://MUSHA.org)  
/ ) ) ) ) / [FreeBSD.org](http://FreeBSD.org) / [Ruby-lang.org](http://Ruby-lang.org)  
Akinori MUSHA aka / (\_ / ( (\_\_( @ [iDaemons.org](http://iDaemons.org) / and.or.jp

“Different eyes see different things,  
Different hearts beat on different strings –  
But there are times for you and me when all such things agree”

---

<div class="post-metadata">

**Author:** ![OHARA\_Shigeki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c37758/32.png) [@OHARA\_Shigeki](https://www.ruby-forum.com/u/OHARA_Shigeki)\
**Post date:** [March 5, 2007, 2:15pm UTC](https://www.ruby-forum.com/t/time-to-s-format/87702/3 "2007-03-05T14:15:33Z")

</div>

ã€€ã¨ã“ã‚ã§ã€ 1.8.6 ã® Time#to\_s ã‚’ RFC 2822 å½¢å¼ã«ã™ã‚‹ã¨ã„ã†ã®ã¯  
æœ€çµ‚æ±ºå®šã§ã„ã„ã®ã§ã—ã‚‡ã†ã‹ã€‚1.9 ã§ã¯ã¾ãŸé•ã†å½¢å¼ã«ãªã£ã¦ã„ã¾ã™ãŒã€  
ã“ã‚Œã¯å¤‰æ›´ã—å¿˜ã‚Œã§ã™ã‚ˆã­ï¼Ÿ

ã€€1.9 ã§ã¾ãŸå¤‰ãˆã‚‹ãã‚‰ã„ãªã‚‰ã€ 1.8.6 ã§å¤‰ãˆã‚‹ã®ã¯é¿ã‘ãŸã„ã®ã§ã™ãŒã€‚

–  
/  
/\_\_ \_\_ [Akinori.org](http://Akinori.org) / [MUSHA.org](http://MUSHA.org)  
/ ) ) ) ) / [FreeBSD.org](http://FreeBSD.org) / [Ruby-lang.org](http://Ruby-lang.org)  
Akinori MUSHA aka / (\_ / ( (\_\_( @ [iDaemons.org](http://iDaemons.org) / and.or.jp

“Different eyes see different things,  
Different hearts beat on different strings –  
But there are times for you and me when all such things agree”

---

<div class="post-metadata">

**Author:** ![OHARA\_Shigeki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c37758/32.png) [@OHARA\_Shigeki](https://www.ruby-forum.com/u/OHARA_Shigeki)\
**Post date:** [March 6, 2007, 7:38am UTC](https://www.ruby-forum.com/t/time-to-s-format/87702/4 "2007-03-06T07:38:49Z")

</div>

At Mon, 5 Mar 2007 23:27:33 +0900,  
matz wrote:

> Timezoneè¡¨ç¾ã®éƒ¨åˆ†ã‚’æ•°å€¤è¡¨ç¾ã«ã™ã‚‹ã“ã¨ã ã‘ã ã£ãŸã®ã§ã™ãŒã€  
> Timezonè¡¨ç¾ã®ä½ç½®ã«ã¤ã„ã¦æ‚©ã‚“ã§ã„ã‚‹ã†ã¡ã«ãã®ã¾ã¾RFC2822å½¢å¼  
> ã«ãªã£ã¦ã—ã¾ã£ãŸã¨ã„ã†çµŒç·¯ãŒã‚ã‚Šã¾ã™(å½“åˆã€RFC2822ã¨ctimeå½¢  
> å¼ã®é•ã„ã‚’ååˆ†ã«èªè­˜ã—ã¦ã„ãªã‹ã£ãŸ)ã€‚

ã€€æœ¬å½“ã« RFC 2822 å½¢å¼ãŒæ¬²ã—ã„ãªã‚‰ãã‚Œç”¨ã®ãƒ¡ã‚½ãƒƒãƒ‰(time.rb ã®  
Time#rfc2822 ãªã‚Šè‡ªä½œãƒ¡ã‚½ãƒƒãƒ‰ãªã‚Š)ã‚’ä½¿ã†ã¹ããªã®ã§ã€ to\_s ãŒ  
RFC 2822 å½¢å¼ã§ã‚ã‚‹å¿…è¦ã¯ãªã„ã§ã—ã‚‡ã†ã­ã€‚

ã€€ãã‚Œã¯ã•ã¦ãŠãã€ inspect ã¯ usec ã‚’å«ã‚€å½¢å¼ã«å¤‰ãˆãŸæ–¹ãŒã„ã„ã‚“  
ã˜ã‚ƒãªã„ã§ã—ã‚‡ã†ã‹ã€‚(ctime ã‚„ RFC 2822 ã¯ usec ã‚’å«ã‚ã‚‰ã‚Œãªã„)

> ã§ã€Ruby 1.9ã§ã¯ISO8601å½¢å¼(ãŸã ã—åŒºåˆ‡ã‚Šã®Tã¯ä½¿ã‚ãªã„)ã«ã—ã‚ˆ  
> ã†ã¨æ€ã£ã¦ã„ã¾ã™ã€‚å…ƒã€…1.8ã®ç¯„å›²å†…ã§ã¯å°ã•ãªå¤‰æ›´ã«ã—ã¦ã€1.9ã®  
> ã¨ãã«å¤§ããªå¤‰æ›´ã«ã—ã‚ˆã†ã¨æ€ã£ã¦ã„ã¾ã—ãŸã‹ã‚‰ã€‚

ã€€1.9 ã® rdoc ã¯å®Ÿè£…ã‚’åæ˜ ã—ã¦ã„ã¾ã›ã‚“ã€‚ä»Šã®ä»•æ§˜ã¯ ISO 8601  
ã§ã‚‚ YAML æº–æ‹ ã§ã‚‚ãªãä¸­é€”åŠç«¯ãªã®ã§ã€ã“ã®æ©Ÿä¼šã«å®Ÿè£…ã‚‚å¤‰ãˆã¦  
ã—ã¾ã£ãŸæ–¹ãŒã„ã„ã¨æ€ã„ã¾ã™ãŒã€‚

# Index: time.c

— time.c (revision 11998)  
+++ time.c (working copy)  
@@ -1185,11 +1185,14 @@

- 

```
time.to_s => string

```

- 
- Returns a string representing _time_. Equivalent to calling

- 
  - `Time#strftime` with a format string of  
```%a`

- 
  - `%b` `%d` `%H:%M:%S`

- 
  - `%Z` `%Y`‘’.

- 
  - `Time#strftime` with a format string of

- 
  - ```%Y-%m-%d` `%H:%M:%S` `%z`‘’

- 
  - for local times and

- 
  - ```%Y-%m-%d` `%H:%M:%S` `UTC`‘’

- 
  - for UTC times.
  - 

- 
  - 

```
Time.now.to_s #=> "Wed Apr 09 08:56:04 CDT 2003"

```

- 
  - 

```
Time.now.to_s #=> "2003-04-09 08:56:04 -0500"

```

- 
  - 

```
Time.now.utc.to_s #=> "2003-04-09 13:56:04 UTC"

```

\*/

static VALUE

> ã¨ã„ã†ã‚ã‘ã§ã€ä»Šã•ã‚‰ã§ã¯ã‚ã‚Šã¾ã™ãŒã€ç§ã¯
> 
> - 1.8ã®ç¯„å›²å†…ã§ã¯RFC2822ã¯æŽ¡ç”¨ã›ãšã€Timezoneã‚’æ•°å€¤è¡¨ç¾ã«ã™  
> ã‚‹ã ã‘(ã¤ã¾ã‚Šã€1.8.5ã®çŠ¶æ…‹ã«æˆ»ã™)
> 
> - 1.9ã§ISO8601å½¢å¼ã«
> 
> ã¨ã„ã†ã®ã‚’ææ¡ˆã—ã¾ã™ã€‚ãŒã€ã™ã£ã‹ã‚Šå¿˜ã‚Œã¦æ”¾ç½®ã—ã¦ã„ãŸã®ã¯ç§ã§  
> ã™ã—ã€ã‚‚ã†æ™‚æœŸã‚‚æ™‚æœŸã§ã™ã‹ã‚‰ã€æœ€çµ‚çš„ãªåˆ¤æ–­ã¯knuã•ã‚“ã«ä»»ã›ã¾  
> ã™ã€‚

ã€€å¤‰ãˆã‚‹ã«è¶³ã‚‹ç†ç”±ãŒè¦‹ã¤ã‹ã‚‰ãªã„ã®ã§ã€ 1.8.6 ã¯ 1.8.5 ã®ä»•æ§˜ã«  
æˆ»ãã†ã¨æ€ã„ã¾ã™ã€‚ã‚‚ã£ã¨æ—©ãçªã£è¾¼ã‚“ã§ãŠã‘ã°ã‚ˆã‹ã£ãŸã€‚

–  
/  
/\_\_ \_\_ [Akinori.org](http://Akinori.org) / [MUSHA.org](http://MUSHA.org)  
/ ) ) ) ) / [FreeBSD.org](http://FreeBSD.org) / [Ruby-lang.org](http://Ruby-lang.org)  
Akinori MUSHA aka / (\_ / ( (\_\_( @ [iDaemons.org](http://iDaemons.org) / and.or.jp

“Different eyes see different things,  
Different hearts beat on different strings –  
But there are times for you and me when all such things agree”

---

<div class="post-metadata">

**Author:** ![OHARA\_Shigeki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c37758/32.png) [@OHARA\_Shigeki](https://www.ruby-forum.com/u/OHARA_Shigeki)\
**Post date:** [March 5, 2007, 3:28pm UTC](https://www.ruby-forum.com/t/time-to-s-format/87702/5 "2007-03-05T15:28:44Z")

</div>

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:30493] Re: Time#to\_s format”  
on Mon, 5 Mar 2007 22:15:13 +0900, “Akinori MUSHA”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|e$B!!$H$3$m$G!"e(B 1.8.6 e$B$Ne(B Time#to\_s e$B$re(B RFC 2822 e$B7A\<0$K$9$k$H$$$&$N$Oe(B  
|e$B:G=\*7hDj$G$$$$$N$G$7$g$&$+!#e(B1.9 e$B$G$O$^$?0c$&7A\<0$K$J$C$F$$$^$9$,!"e(B  
|e$B$3$l$OJQ99$7K:$l$G$9$h$M!)e(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div class="post-metadata">

**Author:** ![OHARA\_Shigeki](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c37758/32.png) [@OHARA\_Shigeki](https://www.ruby-forum.com/u/OHARA_Shigeki)\
**Post date:** [March 9, 2007, 9:17am UTC](https://www.ruby-forum.com/t/time-to-s-format/87702/6 "2007-03-09T09:17:18Z")

</div>

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:30499] Re: Time#to\_s format”  
on Tue, 6 Mar 2007 15:38:38 +0900, “Akinori MUSHA”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) writes:

|e$B!!$=$l$O$5$F$\*$-!"e(B inspect e$B$Oe(B usec e$B$r4^$`7A\<0$KJQ$($?J}$,$$$$$se(B  
|e$B$8$c$J$$$G$7$g$&$+!#e(B(ctime e$B$de(B RFC 2822 e$B$Oe(B usec e$B$r4^$a$i$l$J$$e(B)

e$B$=$&$G$9$M$(!#e(BYAMLe$B7A\<0$K$“$o$;$k$+$J$”!#e(B

|\> e$B$G!"e(BRuby 1.9e$B$G$Oe(BISO8601e$B7A\<0e(B(e$B$?$@$76h@Z$j$Ne(BTe$B$O;H$o$J$$e(B)e$B$K$7$he(B  
|\> e$B$&$H;W$C$F$$$^$9!#85!9e(B1.8e$B$NHO0OFb$G$O\>.$5$JJQ99$K$7$F!“e(B1.9e$B$Ne(B  
|\> e$B$H$-$KBg$-$JJQ99$K$7$h$&$H;W$C$F$$$^$7$?$+$i!#e(B  
|  
|e$B!!e(B1.9 e$B$Ne(B rdoc e$B$O\<BAu$rH?1G$7$F$$$^$;$s!#:#$N;EMM$Oe(B ISO 8601  
|e$B$G$be(B YAML e$B=`5r$G$b$J$/CfESH\>C\<$J$N$G!”$3$N5!2q$K\<BAu$bJQ$($Fe(B  
|e$B$7$^$C$?J}$,$$$$$H;W$$$^$9$,!#e(B

e$B$=$&$G$9$M!#8=\>ue(BISO8601e$B$K9g$C$F$J$$ItJ,$,$“$k$N$O3N$+$G$9!#e(B  
e$B%?%$%`%\>!\<%s$N!Ve(BZe$B!W$,5$$KF~$i$J$$$s$G$9$h$M$(!#e(B  
e$BBE6($9$k$+$J$”!#e(B
