Skip to content

Instantly share code, notes, and snippets.

View cp-sumi-k's full-sized avatar

Sumita Canopas cp-sumi-k

View GitHub Profile
// Hours of date in 12 hours format (ha) : 5 pm
console.log(cDate.toLocaleString("default", { hour: "numeric", hour12: true }))
// MMM : Nov
console.log(cDate.toLocaleString('default', { month: 'short' })
// MMM YY : Nov 22
console.log(cDate.toLocaleString('default', { month: 'short', year: '2-digit' })
// DD MMM YY : 07 Nov 22
// Current timezone is : Asia/Calcutta
console.log("Current timezone is : " , Intl.DateTimeFormat().resolvedOptions().timeZone)
// Current date in America/Los_Angeles : 11/7/2022, 2:59:43 AM
console.log("Current timezone is : " , cDate.toLocaleString("en-US", { timeZone: "America/Los_Angeles" }))
// Current date in millis : 1667813042954
// A year after : 1699353114157
console.log("A year after : ", new Date().setYear(cDate.getFullYear() + 1))
// 3 months after : 1675765990138
console.log("3 months after : ", new Date().setMonth(cDate.getMonth() + 3))
// 2 days after : 1667990027784
console.log("2 days after : ", new Date().setDate(cDate.getDate() + 2))
// Current date in millis : 1667813042954
// A year ago : 1636280463554
console.log("A year ago : ", new Date().setYear(cDate.getFullYear() - 1))
// 3 months ago : 1659867711241
console.log("3 months ago : ", new Date().setMonth(cDate.getMonth() - 3))
// 2 days ago : 1667643213795
console.log("2 days ago : ", new Date().setDate(cDate.getDate() - 2))
/** year **/
// Current year : 2022
console.log("Current year : ", new Date().getFullYear())
// Given date year : 2018
console.log("Given date year : ", new Date("2018-03-25").getFullYear())
/**
month
// https://docs.google.com/spreadsheets/d/<SPREADSHEETID>/edit#gid=<SHEETID>
spreadsheetId := <SPREADSHEETID>
// The A1 notation of cells range to update.
range2 := "A1:C1"
// prepare data for update cells
row := &sheets.ValueRange{
Values: [][]interface{}{{"2", "XYZ", "xyz@gmail.com"}},
}
// https://docs.google.com/spreadsheets/d/<SPREADSHEETID>/edit#gid=<SHEETID>
sheetId := <SHEETID>
spreadsheetId := <SPREADSHEETID>
records := []string{"1", "ABC", "abc@gmail.com"}
// create the batch request
batchUpdateRequest := sheets.BatchUpdateSpreadsheetRequest{
Requests: []*sheets.Request{
{
func prepareCells(records []string) []*sheets.RowData {
// init cells array
cells := []*sheets.CellData{}
bgWhite := &sheets.Color{ // green background
Alpha: 1,
Blue: 0,
Red: 0,
Green: 1,
}
// https://docs.google.com/spreadsheets/d/<SPREADSHEETID>/edit#gid=<SHEETID>
sheetId := <SHEETID>
spreadsheetId := <SPREADSHEETID>
// Convert sheet ID to sheet name.
response1, err := srv.Spreadsheets.Get(spreadsheetId).Fields("sheets(properties(sheetId,title))").Do()
if err != nil || response1.HTTPStatusCode != 200 {
log.Error(err)
return
}
// create api context
ctx := context.Background()
// get bytes from base64 encoded google service accounts key
credBytes, err := b64.StdEncoding.DecodeString(os.Getenv("KEY_JSON_BASE64"))
if err != nil {
log.Error(err)
return
}