nodejs moment moment-timezone

Use express, moment, moment-timezone const moment = require('moment-timezone'); app.get('/moment', (req, res) => { const datestr = '2020-07-01'; res.status(200).json({ local_offset: moment(datestr).utc(), local_unix: moment(datestr).unix(), zone0_unix: moment(datestr).zone(0).unix(), zone8_unix: moment(datestr).zone(8).unix(), timezone0_unix: moment.tz(datestr, 'GMT').unix(), timezone8_unix: moment.tz(datestr, 'Asia/Taipei').unix(), }); }); // No use, just for keep function dateForTimezone(offset, d) { // Copy date if supplied or use current d = d? new Date(+d) : new Date(); // Use supplied offset or system offset = offset || -d.getTimezoneOffset(); // Prepare offset values var offSign = offset < 0? '-' : '+'; offset = Math.abs(offset); var offHours = ('0' + (offset/60 | 0)).slice(-2); var offMins = ('0' + (offset % 60)).slice(-2); // Apply offset to d d.setUTCMinutes(d.getUTCMinutes() - offset); return offSign + offHours + ':' + offMins; // Return formatted string return d.getUTCFullYear() + '-' + ('0' + (d.getUTCMonth()+1)).slice(-2) + '-' + ('0' + d.getUTCDate()).slice(-2) + 'T' + ('0' + d.getUTCHours()).slice(-2) + ':' + ('0' + d.getUTCMinutes()).slice(-2) + ':' + ('0' + d.getUTCSeconds()).slice(-2) + '.' + ('000' + d.getUTCMilliseconds()).slice(-3) + offSign + offHours + ':' + offMins; } IMPORT Server timezone 0 ...

2020-04-15 · 2 min · 233 words · Me

typeorm connection

const typeorm = require("typeorm"); const connectionManager = require("typeorm").getConnectionManager(); //const connectionManager = typeorm.getConnectionManager(); const connected = connectionManager.has("default"); if(!connected){ // ? load connection options from ormconfig or environment //const connectionOptions = await getConnectionOptions(); connectionManager.create({ //name: "default", type: "mysql", // "extra": { // "socketPath": "/cloudsql/ooxxooxx" // }, host: "oo.xx.oo.xx", port: 3306, username: "root", password: "ooxxooxx", database: "ooxxdb", synchronize: false, logging: true, // this.env === 'dev' ? true : false ssl: SSL, keepConnectionAlive: false, }); } try { db = connectionManager.get(); if(!connected){ await db.connect(); console.log('connect .... OK!'); } }catch(error) { console.log("TypeORM Error: ", error); }; var ranks = await db.query("select * from users");

2020-04-14 · 1 min · 99 words · Me

Sequelize 基本認識

# Sequelize 基本認識 ## 1. Timestamps https://sequelize.org/v5/manual/models-definition.html#timestamps ## 2. Database synchronization https://sequelize.org/v5/manual/models-definition.html#database-synchronization 建議不要直接使用於正式環境,應該在測試建立後,取得對應 sql 碼後,在正式上線時,手動更新正式 DB 資料結構 **2.1** 使用 sync 建立的 table name 會加上 s **2.2** 正常情況下,對 table 操作盡可能還是已手動為主,雖然 Sequelize 有提供一些操作,但減少使用比較安全,當手動操作完畢後,應該把 raw sql 匯出備份,正式上線時,再手動更新 ## 3. Modeling a table 建立 https://sequelize.org/v5/manual/getting-started.html ``` const Model = Sequelize.Model; class User extends Model {} User.init({ ``` 建議使用 ``` sequelize.define:‘user’, { // attributes firstName: { ``` 原因,看起來簡單多了 3.1 Model 操作 https://sequelize.org/v5/manual/models-usage.html ## 4. Raw queries https://sequelize.org/v5/manual/raw-queries.html 基本當join比較複雜建議使用,因為清楚、效率可控,或更複雜的 sub sql 都可以進行,避免 ORM 處理不當,造成效能大幅下降 ...

2020-04-09 · 1 min · 89 words · Me

西方式傲慢

西方式傲慢 https://youtu.be/-3lqr6Ys_zQ?t=697 中國為西方贏得時間,西方卻浪費了它 張彥 https://cn.nytimes.com/opinion/20200314/china-response-china/zh-hant/ 普立茲獎 張彥 https://zh.wikipedia.org/zh-tw/%E5%BC%A0%E5%BD%A6_(%E7%BE%8E%E5%9B%BD%E8%AE%B0%E8%80%85) 連 柳葉刀的主編 中國傳遞了非常清淅的訊息,可是我們浪費了整整2個月 https://news.sina.com.tw/article/20200401/34733366.html https://www.facebook.com/watch/?v=538201007134058

2020-04-06 · 1 min · 13 words · Me

[轉]Go 交叉編譯

https://ithelp.ithome.com.tw/articles/10225188 在Windows上編譯 To MacOs SET CGO_ENABLED=0 SET GOOS=darwin SET GOARCH=amd64 go build main.go To Linux SET CGO_ENABLED=0 SET GOOS=linux SET GOARCH=amd64 go build main.go To Windows ??? go build main.go 在Linux上編譯 CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build main.go CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build main.go CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build main.go

2020-03-26 · 1 min · 49 words · Me