Choose to show the current time in PST by converting milliseconds

Currently, I am working on Javascript and dealing with time in milliseconds. I have been successful in displaying the time in GMT format but now I need to convert it to PST timezone. The challenge is that the input time is in milliseconds (e.g. 1671673550214) and I am trying to figure out how to display it in PST format. I have attempted using UTCString(), UTC() and toString(), however, the output always ends up being converted to GMT instead of PST.

var time = new Date().getTime();
var date = new Date(time);
document.write(date.toString());

If there's an alternative method or solution to converting milliseconds to PST timezone, please provide assistance.

Answer №1

I highly recommend checking out this amazing library that offers a wide range of functions for manipulating date and time information.

http://momentjs.com/ http://momentjs.com/docs/

For more resources on handling dates and times, I suggest taking a look at the following helpful post:

Moment.js: Format date in a specific timezone\

If you prefer not to rely on external libraries, consider reading through this informative article that explains how to convert local time to another time zone using JavaScript:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The Dropdown Button Functions Once and Then Stops

I am facing a challenge in implementing a button within an HTML table that triggers a dropdown menu when clicked, and closes upon another click or when the user clicks outside the menu. Oddly, the button only seems to work once before completely losing fun ...

Guide to repeatedly printing an array a set number of times

Consider the following array: var arr = ['a','b','c','d']; Your task is to prompt the user to input a number, for instance: 6, 7, 10, or any other number. Let's assume that the user enters: 10 The desired ou ...

Having difficulty locating the xpath list, attempting to utilize a wildcard to search for text or style

My task is to locate the XPath for the section under “Main Lists” on this specific site. This is what I have so far: //div[starts-with(@class, ('sm-CouponLink_Label'))] However, this search yields 32 results... `//div[starts-with(@class, ( ...

What is the best way to set a specific maximum size for the dropdown selector in Material UI's TextField component?

Working on a Sign up Page involves prompting users to select their location from a dropdown list of different countries. However, the issue arises when the dropdown list covers the entire screen, making it difficult for users to navigate. Is there a way to ...

Utilize Bootstrap 3 Datepicker version 4 to easily set the date using Moment.js or Date objects

I'm currently utilizing the Within my project, I have a datetime picker labeled as dtpFrom <div class='input-group date ' id='dtpFrom'> <input type='text' class="form-control" /> <span c ...

Issue with a input element having relative positioning within a flexbox

Objective: Aim to align the middle DIV (MIDDLE) within a flexbox row in the center. Issue: The right element includes an input element with relative positioning. Consequently, the middle DIV element (MIDDLE) is no longer centered but instead shifted to th ...

Utilize resources from webpack's bundled npm package assets

I've been racking my brain over this issue for quite some time now, and I'm starting to wonder if it's even achievable. Any assistance on this matter would be greatly appreciated! The npm dilemma I have an npm package that serves as a coll ...

How do I use Puppeteer to save the current page as a PDF?

Is it possible to convert a web page in a React project to PDF and download it upon clicking a button? ...

I'm having trouble with my react-big-calendar not updating when I switch between day, month, or week views -

Why won't my calendar change to the week view when I click on that section? https://i.stack.imgur.com/gh2aO.png In the screenshot above, my default view is set to month, but when I attempt to switch to week, it only highlights the option without cha ...

What is the best way to arrange divs in varying order across different breakpoints?

I am currently utilizing Bootstrap and aiming to achieve a specific layout as shown below: https://i.sstatic.net/dZ4Tt.png The numbers are indicating the desired order of the divs in a single column on mobile devices. The HTML code I attempted is as foll ...

Is there a way to direct to a specific URL upon clicking a button using PHP?

In my PHP code called registerprocess.php, it executes after clicking a submit button on another page named userregistration.php. If a user tries to register with an email that already exists in the database, I want registerprocess.php to redirect back to ...

jQuery failing to load Ajax content

As a beginner, I am attempting to use ajax with XAMPP to load text from a local file using jQuery. Despite my efforts, the data is not loading into my div. Can someone help me troubleshoot this? See below for the code snippet: Jquery <script src="http ...

A guide on incorporating a React custom package within an Angular directive

Hey there, I have an Angular v1.x application and a React custom package. I'm looking to integrate the React custom package into my Angular directive, so that it can display a React component. Here's some code snippet: Angul ...

What is the best way to align a button within a Jumbotron?

Struggling to find the right CSS placement for a button within a jumbotron. I attempted using classes like text-left or pull-left, but nothing seemed to work as I hoped. I believe a simple CSS solution exists, but it's eluding me at the moment. Ideall ...

Footer that sticks in a vuejs application

I am facing a challenge in implementing a sticky footer in my vuejs application. Vuejs and similar frameworks require the presence of a root element in the template. This requirement is causing complications when trying to use Flex to create a sticky foo ...

Step-by-step guide to implementing onClick functionality within a component

Currently, I am utilizing https://github.com/winhtaikaung/react-tiny-link to showcase posts from various blogs. While I am able to successfully retrieve the previews, I am facing an issue with capturing views count using onClick(). Unfortunately, it appear ...

Having trouble with the find method when trying to use it with the transform

In my code, I have three div elements with different values of the transform property assigned to them. I store these elements in a variable using the getElementsByClassName method and then try to find the element where the value of the transform property ...

Encountering a StaleElementReferenceException with Python Selenium when trying to loop through Select dropdown

Tasked with creating a selenium test in Python for a webpage without access to the source code, I am facing challenges due to encountering a StaleElementReferenceException randomly while trying to extract dropdown menu options. The website uses D3 and JQue ...

Tips for adjusting the autocomplete maxitem dynamically

I am working on a multi autocomplete feature and I have the following code. Is there a way to dynamically set the maximum number of items based on the value entered in another text field? <script> $(function () { var url2 = "<?php echo SI ...

The conditional logic in AngularJS is not functioning as expected

https://i.sstatic.net/RvqYQ.pngMy code seems to have an issue with the if/else statement. I am checking the value of data.success which should contain either true or false. However, when I use (data.success === true) in the if statement, the else block e ...