###### tags: `javascript`,`C#`,`前端`,`2021`
# 取得UTC時間戳記
## Javascript
```javascript=
//時間取到小時
function GetUTCTimespan() {
var now = new Date();
var timestamp = Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), now.getUTCHours(), 0, 0, 0);
return Math.floor(timestamp / 1000);
}
```
## C#
```csharp=
private string GetTimeSpanbyNow(DateTime now)
{
DateTime myDate = new DateTime(now.Year, now.Month, now.Day, now.Hour, 0,0);
long unixTimestamp = (long)(myDate.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
return unixTimestamp.ToString();
}
```
線上timespan轉換工具: [timespan online](https://timestamp.online/countdown/1627500000)