How to use the utc function from moment-timezone

Find comprehensive JavaScript moment-timezone.utc code examples handpicked from public code repositorys.

moment-timezone.utc is a function in Moment.js that returns the current time in Coordinated Universal Time (UTC) timezone.

-1
fork icon23
star icon292
watch icon19

+ 3 other calls in file

272
273
274
275
276
277
278
279
280
281
282
// Generic timestamp formatter
const formatTimeStamp = (dateStr, format) => {
  const date = new Date(dateStr);
  // moment format is passed. format accordingly
  if (format) {
    return moment.utc(date).format(format);
  }


  // return default format
  return date.getTime();
fork icon77
star icon54
watch icon20

+ 4 other calls in file

How does moment-timezone.utc work?

moment-timezone is a library that allows handling and manipulation of dates and times with respect to different time zones. The moment-timezone.utc() function returns a Moment object representing the current date and time in the UTC time zone.

48
49
50
51
52
53
54
55
56
57
    else
        return 'never';
}

app.locals.utc = function () {
    return moment.utc();
}

app.locals.add = function (date, amount, unit) {
    return moment(date).add(amount, unit);
fork icon3
star icon10
watch icon2

+ 9 other calls in file

225
226
227
228
229
230
231
232
233
234
);

/**
 * @type {string}
 */
const currentDate = moment.utc().format('YYYY-MM-DD');

// noinspection JSCheckFunctionSignatures
try {
    let {/** @type {string} */ base_version} = parsedArgs;
fork icon1
star icon13
watch icon0

Ai Example

1
2
3
4
const moment = require("moment-timezone");

const now = moment.utc();
console.log(now.format()); // prints the current date and time in UTC

In this example, we first require the moment-timezone module and create a new moment object using the moment.utc() function, which creates a moment object representing the current date and time in UTC. We then use the format() function to print the date and time in the default format.

569
570
571
572
573
574
575
576
577
578
formatTimeUTC: function (value, format='HH:mm') {
    if(!value)
    {
        return "";
    }
    return moment.utc(value).format(format);
},
//---------------------------------------------------------------------
formatDateTimeUTC: function (value) {
    if(!value)
fork icon1
star icon4
watch icon3

+ 2 other calls in file

94
95
96
97
98
99
100
101
102
103
 * Perform a single run of the checks for pending scheduled tasks.
 *
 * @returns {Promise<void>} Resolves when the work for this tick is finished.
 */
async tick() {
  const now = moment.utc();
  const votesByGuild = Object.entries(this.ongoingVotes);

  for (const [guild, votes] of votesByGuild) {
    const endingVotes = votes.filter((vote) => vote.due.isSameOrBefore(now));
fork icon0
star icon0
watch icon0

318
319
320
321
322
323
324
325
326
327
});

it('Can reply to your own comment', async function () {
    // Should not update last_seen_at or last_commented_at when both are already set to a value on the same day
    const timezone = settingsCache.get('timezone');
    const date = moment.utc(new Date()).tz(timezone).startOf('day').toDate();
    await models.Member.edit({last_seen_at: date, last_commented_at: date}, {id: member.get('id')});

    await membersAgent
        .post(`/api/comments/`)
fork icon0
star icon0
watch icon1

+ 8 other calls in file

40
41
42
43
44
45
46
47
48
49
50
51
52




// Obtener bitacora
exports.getRecord = async (socialEmployee = undefined) => {
   const dateStart = moment(moment.tz('America/Bogota')).add(-1, 'd').startOf('day').utc().format('YYYY-MM-DD HH:mm:ss');
   const dateEnd = moment.utc(moment.tz('America/Bogota')).format();
};


// update service
async function updateService(serviceId, setChanges) {
fork icon0
star icon0
watch icon1

+ 3 other calls in file

86
87
88
89
90
91
92
93
94
95
onSave() {

  if (this.props.conditionToChange === false) {
    this.props.editPublishedEvent(this.props.publishedEvent.id, {
      text: this.state.text,
      date: moment.utc().format()
    })
  } else {
    this.props.editUnpublishedEvent(this.props.unpublishedEvent.id, {
      text: this.state.text,
fork icon0
star icon0
watch icon0

52
53
54
55
56
57
58
59
60
61
const user = await client.get('users/me', { responseType: 'json' }).json()

const { timezone } = user

if (!from && !to && !meetingId) {
  const end = cursor && moment.utc(cursor).endOf('day').tz(timezone || 'UTC')
  return initializeData(user, end)
}

if (from && to) {
fork icon0
star icon0
watch icon332

+ 5 other calls in file