You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过ServiceNow RestAPI为日期时间字段传入毫秒值(1568895389)

How to Pass Millisecond Timestamps to ServiceNow DateTime Fields via REST API

Alright, let's walk through exactly how to get that timestamp (your example 1568895389) into a ServiceNow DateTime field via their REST API. Here's what you need to know:

  • First, note that your given timestamp is second-level Unix time (10 digits). ServiceNow's DateTime fields expect either a millisecond-level Unix timestamp (13 digits) or an ISO 8601 formatted string with milliseconds. So first step: convert your 10-digit timestamp to 13 digits by multiplying by 1000. For your example, that gives 1568895389000.

  • There are two straightforward ways to send this value in your API request:

Option 1: Send the Millisecond Timestamp as a Numeric Value

This is the simplest approach if you don't want to mess with date formatting. Just include the 13-digit timestamp directly in your JSON payload as a number (no quotes):

{
  "your_date_time_field_name": 1568895389000
}

Option 2: Convert to an ISO 8601 String with Milliseconds

If you prefer using formatted dates, convert the millisecond timestamp to an ISO 8601 string (including .000 for milliseconds, since your original timestamp doesn't have fractional seconds). For your example, that would be 2019-09-19T12:16:29.000Z (UTC time). Include this as a quoted string in your payload:

{
  "your_date_time_field_name": "2019-09-19T12:16:29.000Z"
}
  • A few critical notes to avoid issues:
    • ServiceNow stores DateTime values in UTC by default. If your original timestamp is in a local timezone, make sure to adjust it to UTC before converting, or use an ISO string with a timezone offset (e.g., 2019-09-19T08:16:29.000-04:00 for Eastern Daylight Time).
    • Always set the Content-Type: application/json header in your request, and authenticate properly (Basic Auth, OAuth, etc.) as required by your ServiceNow instance.
    • Here's a quick curl example to test creating an incident with the timestamp:
      curl -X POST \
        https://your-instance.service-now.com/api/now/table/incident \
        -H 'Authorization: Basic YOUR_BASE64_ENCODED_CREDENTIALS' \
        -H 'Content-Type: application/json' \
        -d '{
          "short_description": "Test DateTime with milliseconds",
          "opened_at": 1568895389000
        }'
      

Just pick whichever option fits your workflow better—both will work as long as you stick to the millisecond requirement.

内容的提问来源于stack exchange,提问作者Moni

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 07:59:31