

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 在 GLV 時間資料使用原生日期和時間
<a name="best-practices-gremlin-datetime-glv"></a>

如果您是使用 Gremlin 語言變體 (GLV)，必須使用該程式語言為 Gremlin 時間資料提供的原生日期和時間類別與函數。

官方 TinkerPop 程式庫都是 Gremlin 語言變體程式庫。
+  [Go](https://tinkerpop.apache.org/docs/current/reference/#gremlin-go) 
+  [Java](https://tinkerpop.apache.org/docs/current/reference/#gremlin-java) 
+  [Javascript](https://tinkerpop.apache.org/docs/current/reference/#gremlin-javascript) 
+  [.NET](https://tinkerpop.apache.org/docs/current/reference/#gremlin-dotnet) 
+  [Python](https://tinkerpop.apache.org/docs/current/reference/#gremlin-python) 

**重要**  
 此頁面僅適用於 Gremlin 語言變體 (GLV) 程式庫。如果您使用將 Gremlin 查詢作為文字字串傳送的方法，則必須使用 Gremlin 的日期時間 () 函數。這包括 Gremlin 主控台、使用 HTTP REST API 的文字字串，或透過驅動程式直接提交 Gremlin 字串。



**Go**  
 以下是 Go 中的部分範例，該範例會為 ID 為 '3' 的頂點建立名為 'date' 的單一屬性。它將值設定為使用 Go time.Now() 函數產生的日期。

```
import ( "time" )

g.V('3').property('date', time.Now()).next();
```

如需使用 Go 連線至 Neptune 的完整範例，請參閱[使用 Go 用戶端連線至 Neptune 資料庫執行個體](https://docs.aws.amazon.com//neptune/latest/userguide/access-graph-gremlin-go.html)。

**Java**  
以下是 Java 範例的一部分，它會為頂點建立一個名為 '`date`' 且 ID 為 '`3`' 的屬性。它將值設為使用 Java `Date()` 建構函數產生的日期。

```
import java.util.date

g.V('3').property('date', new Date()).next();
```

如需使用 Java 連線至 Neptune 的完整範例，請參閱 [使用 Java 連線至 Neptune 資料庫執行個體](access-graph-gremlin-java.md)。

**Node.js (JavaScript)**  
以下是 JavaScript 範例的一部分，它會為頂點建立一個名為 '`date`' 且 ID 為 '`3`' 的屬性。它將值設為使用 Node.js `Date()` 建構函數產生的日期。

```
g.V('3').property('date', new Date()).next()
```

如需使用 Node.js 連線至 Neptune 的完整範例，請參閱 [使用 Node.js 連線至 Neptune 資料庫執行個體](access-graph-gremlin-node-js.md)。

**.NET (C\$1)**  
以下是 C\$1 範例的一部分，它會為頂點建立一個名為 '`date`' 且 ID 為 '`3`' 的屬性。它將值設為使用 .NET `DateTime.UtcNow` 屬性產生的日期。

```
Using System;

g.V('3').property('date', DateTime.UtcNow).next()
```

如需使用 C\$1 連線至 Neptune 的完整範例，請參閱 [使用 .NET 連線至 Neptune 資料庫執行個體](access-graph-gremlin-dotnet.md)。

**Python**  
以下是 Python 範例的一部分，它會為頂點建立一個名為 '`date`' 且 ID 為 '`3`' 的屬性。它將值設為使用 Python `datetime.now()` 方法產生的日期。

```
import datetime

g.V('3').property('date',datetime.datetime.now()).next()
```

如需使用 Python 連線至 Neptune 的完整範例，請參閱 [使用 Python 連線至 Neptune 資料庫執行個體](access-graph-gremlin-python.md)。