---
source_url: https://www.pubnub.com/docs/sdks/ruby/api-reference/misc
title: Utility Methods API for Ruby SDK
updated_at: 2026-06-11T11:37:29.122Z
sdk_name: PubNub Ruby SDK
sdk_version: 6.0.2
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Utility Methods API for Ruby SDK

PubNub Ruby SDK, use the latest version: 6.0.2

Install:

```bash
gem install pubnub@6.0.2
```

The methods on this page are utility methods that don't fit into other categories.

## Time

This function will return a 17 digit precision Unix epoch.

:::note Algorithm constructing the timetoken
```javascript
timetoken = (Unix epoch time in seconds) * 10000000
```
Convert back and forth between current time and a timetoken:
```javascript
now = Time.now
2012-11-02 14:27:11 -0700
timetoken = now.to_f * 10000000
13518916319742640
Time.at(timetoken / 10000000)
2012-11-02 14:27:11 -0700
```
:::

### Method(s)

To fetch `Time` you can use the following method(s) in Ruby SDK:

```ruby
time(
    http_sync: http_sync,
    callback: callback
)
```

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| http_sync | Boolean | Optional |  | Default `false`. Method will be executed `asynchronously` and will return future, to get it's `value` you can use `value` method. If set to `true`, method will return array of envelopes (even if there's only one `envelope`). For `sync` methods `Envelope` object will be returned. |
| callback | Lambda | Optional |  | `Callback` that will be called for each `envelope`. For `async` methods future will be returned, to retrieve `value` `Envelope` object you have to call `value` method (thread will be locked until the `value` is returned). |

### Sample code

#### Get PubNub timetoken

:::tip Reference code
This example is a self-contained code snippet ready to be run. It includes necessary imports and executes methods with console logging. Use it as a reference when working with other examples in this document.
:::

```ruby
require 'pubnub'

def get_pubnub_timetoken(pubnub)
  pubnub.time do |envelope|
    if envelope.status[:error]
      puts "Error fetching timetoken: #{envelope.status[:error]}"
    else
      puts "PubNub Timetoken: #{envelope.result[:data][:timetoken]}"
    end
  end
end

def main
  # Configuration for PubNub instance
  pubnub = Pubnub.new(
    subscribe_key: ENV.fetch('SUBSCRIBE_KEY', 'demo'),
    user_id: 'myUniqueUserId'
  )

  # Get PubNub timetoken
  get_pubnub_timetoken(pubnub)
end

if __FILE__ == $0
  main
end
```

### Rest response from server

The `time()` function returns a string timetoken in the following format:

```json

```