Sindhu g
Sindhu g

Reputation: 107

Auto Populate Time in Epoch format in DynamoDB

Im pretty new to DynamoDB. Im trying to auto populate createdTimeStamp in epoch Time when I persist my record using JAVA application. So far I couldn't find a solution. I was only able to find how to auto-populate the TimeStamp as String : Auto populate timestamp in DynamoDB

@DynamoDBAutoGeneratedTimestamp(strategy=DynamoDBAutoGenerateStrategy.CREATE)
public Date getCreatedDate() { return createdDate; }
public void setCreatedDate(Date createdDate) { this.createdDate = createdDate; }

@DynamoDBAutoGeneratedTimestamp(strategy=DynamoDBAutoGenerateStrategy.ALWAYS)
public Date getLastUpdatedDate() { return lastUpdatedDate; }
public void setLastUpdatedDate(Date lastUpdatedDate) { this.lastUpdatedDate = lastUpdatedDate; }

Please help how to do something like above to save time as a number (i.e epoch time in milliseconds. ex: 1516169930709)

Upvotes: 2

Views: 3934

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500495

Looking at the source code, it looks like you should just be able to use a Long property:

@DynamoDBAutoGeneratedTimestamp(strategy=DynamoDBAutoGenerateStrategy.ALWAYS)
public Long getLastUpdatedDate() { ... }
public void setLastUpdatedDate(Long value) { ... }

Note that it has to be Long rather than long as per the comment:

Primitives such as long are not supported since the unset (or null) state can't be detected.

Upvotes: 4

Related Questions