Courseiva
User Interface →mediumMultiple Choice

SF-PD2 User Interface Practice Question

A developer is building a Lightning Web Component that needs to display a formatted date and time based on the user's timezone. Which standard JavaScript object, compatible with LWC, should be used to handle this without additional libraries?

⚠ Common exam trap

Candidates frequently select third-party JavaScript libraries or server-side Apex methods, overlooking the built-in browser support for the native Internationalization API.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

✓

Intl.DateTimeFormat

Modern browsers and the LWC environment support the Internationalization API (Intl). This built-in JavaScript object provides robust capabilities for formatting dates, numbers, and currencies according to specific locales and timezones. Using standard APIs is preferred over third-party libraries for better performance and reduced bundle size.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • ✓

    Intl.DateTimeFormat

    Why this is correct

    Intl.DateTimeFormat is a standard JavaScript constructor that enables locale-aware date and time formatting. It is fully supported in LWC and allows developers to pass options such as 'timeZone' and 'locale' to produce strings that are correctly formatted for the user's specific regional settings.

  • ✗

    Moment.js

    Why it's wrong here

    Moment.js was once the industry standard but is now considered a legacy library that is heavy and often unnecessary given modern browser capabilities. While it can be used in LWC via Static Resources, it is not a standard JavaScript object and adds significant overhead to the component's load time.

  • ✗

    Date.toGMTString()

    Why it's wrong here

    The toGMTString() method is an older part of the Date object that returns a string in a fixed format (GMT). It does not provide the flexibility needed for localized formatting or for adjusting to various user-specific timezones, making it unsuitable for a globalized Salesforce application.

  • ✗

    System.now().format()

    Why it's wrong here

    System.now() is an Apex method, not a JavaScript function. While Apex can format dates on the server, doing so requires a round-trip to the database or an Apex controller. For UI-level formatting, it is best practice to use client-side JavaScript APIs to ensure a responsive user experience.

About these practice questions

One of 226 original SF-PD2 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official Salesforce exam blueprint

This SF-PD2 practice question is part of Courseiva's free Salesforce certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the SF-PD2 exam.