Concerting a Date Object into a UNIX Timestamp

Ask a Question related to Ruby, Design and Development.

  1. #1

    Default Concerting a Date Object into a UNIX Timestamp

    Hello beloved Ruby-Community,

    maybe a stupid question because I probably missed something reading the
    reference of "Programming Ruby", but how do I convert a Date Object into
    a UNIX Timestamp (seconds passed since the UNIX epoch)?

    Kind regards,
    Dennis Oelkers
    --
    Dennis Oelkers | Webadministration | Zentraleinrichtung Rechenzentrum
    TU-Berlin | EN-Gebaeude, K042 | Telefon: 030-314-25029

    Key Fingerprint:
    A6 7A B6 90 09 56 E8 32 02 40 6B 27 80 17 00 89 61 E7 CA 6F
    Dennis Oelkers Guest

  2. Similar Questions and Discussions

    1. #40116 [NEW]: using gregorian to jeulian to unix timestamp in date is wonky
      From: marsh dot wayne at gmail dot com Operating system: Windows 2000 SP4 PHP version: 5.2.0 PHP Bug Type: Calendar related...
    2. #39245 [NEW]: date function generate wrong date with 1162083600 timestamp
      From: lohner at aldea dot hu Operating system: Linux PHP version: 5.1.6 PHP Bug Type: Date/time related Bug description: ...
    3. int4 -> unix timestamp -> sql timestamp; abstime?
      Hello, what is the opposite of cast(extract('epoch' from now()) as int)? The only thing I found that works is cast(cast(... as abstime) as...
    4. Date comparisons using UNIX timestamp?
      Hi all, How does one compare dates if one (or both) of the dates is before 1/1/1970? I tried converting the user's input (from selection boxes;...
    5. convert UNIX timestamp
      Hi Scott, All How can I reverse this ? ( Convert date/time format to UNIX timestamp ) Thanks! Jason. Hall, Scott wrote:
  3. #2

    Default Re: Concerting a Date Object into a UNIX Timestamp

    On Wed, 19 Nov 2003 17:15:08 +0100, Dennis Oelkers wrote:
    > maybe a stupid question because I probably missed something reading the
    > reference of "Programming Ruby", but how do I convert a Date Object into
    > a UNIX Timestamp (seconds passed since the UNIX epoch)?
    irb(main):001:0> Time.now.to_i
    => 1069258948
    irb(main):002:0>

    --
    Simon Strandgaard
    Simon Strandgaard Guest

  4. #3

    Default Re: Concerting a Date Object into a UNIX Timestamp

    In [email]pan.2003.11.19.16.23.18.103013@sneakemail.com[/email] Simon Strandgaard <qj5nd7l02@sneakemail.com> wrote:
    > On Wed, 19 Nov 2003 17:15:08 +0100, Dennis Oelkers wrote:
    > > maybe a stupid question because I probably missed something reading the
    > > reference of "Programming Ruby", but how do I convert a Date Object into
    > > a UNIX Timestamp (seconds passed since the UNIX epoch)?
    >
    > irb(main):001:0> Time.now.to_i
    > => 1069258948
    > irb(main):002:0>
    Ah, thank you very much for that helpful (and quick!) response,
    in fact I tried the to_i method, but on a Date object (doh!).

    irb(main):002:0> Date.new(2003, 11, 19).to_i
    NoMethodError: undefined method `to_i' for #<Date: 4905925/2,0,2299161>
    from (irb):2
    irb(main):003:0>

    Kind regards,
    Dennis Oelkers
    --
    Dennis Oelkers | Webadministration | Zentraleinrichtung Rechenzentrum
    TU-Berlin | EN-Gebaeude, K042 | Telefon: 030-314-25029

    Key Fingerprint:
    A6 7A B6 90 09 56 E8 32 02 40 6B 27 80 17 00 89 61 E7 CA 6F
    Dennis Oelkers Guest

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139