Working with Timezones in JavaScript and Selenium IDE without the need for seconds

I am looking to extract the time from a different time zone without including the seconds.

Here is the code I currently have:

javascript{var d = new Date(); d.setTime(new Date( (d.getTime() + (d.getTimezoneOffset() * 60000) ) + (3600000 * (+10) ) )); d.toLocaleTimeString();}

The output displays as 8:32:51 AM

My desired output format is: 8:32 AM

Answer №1

Here is the proposed method to accomplish the task.

let currentDate = new Date(); 

currentDate.setTime(new Date( (currentDate.getTime() + (currentDate.getTimezoneOffset() * 60000) ) + (3600000 * (+10) ) ));

currentDate.toLocaleString([], {hour: '2-digit', minute:'2-digit'});

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

Creating a JavaScript function that calculates the sum of values in a table

Here is a snippet of my HTML code: <TR Row="1" CLASS="ThemeAlignCenter"> <TD id="wrdActive_Row1" style="width: 50px" CLASS="rdThemeDataTableCell"><SPAN id="lblactive_Row1">6</SPAN></TD> .. ...

Encountering issues with parsing a JSON list in AngularJS

Here is the JSON I am attempting to parse: {[{"name":"Technology"},{"name":"Engineering"},{"name":"Business"}]} I encountered the following error: Unexpected token [ in JSON at position 1 at JSON.parse (<anonymous>) at fromJson The data i ...

How can I modify the appearance of the bootstrap scrollbar with scrollspy?

I'm struggling to modify the color of the scrollbar in Bootstrap scrollspy despite having a functional scrollbar. Here is an example of my code: HTML: <body> <div class="container, scrollbar" id="myScrollspy"> <div class=" ...

Having trouble getting a constructor to function properly when passing a parameter in

Here's the code snippet I'm working with: import {Component, OnInit} from '@angular/core'; import {FirebaseListObservable, FirebaseObjectObservable, AngularFireDatabase} from 'angularfire2/database-deprecated'; import {Item} ...

having trouble retrieving 200 status code from Angular server response

Objective: I need to make certain changes to the record locally if the server responds with a 200 code. Problem: I am unable to retrieve the response code or access the 'message' attribute. This is the server response I receive from the HTTP ca ...

How can I extract data from a swiffy animation?

Suppose I am tracking the number of mouse clicks in Flash. To do this, I have utilized the following code: import flash.events.MouseEvent; plus.addEventListener(MouseEvent.CLICK,aaa) var i:int=0; function aaa(e:MouseEvent) { i++; var a:Number ...

"Exploring the power of Selenium with Chromedriver integration in a

Attempting to run integration tests using javascript for my application (Chrome being the browser of choice), I encountered an issue where Capybara failed to detect the Selenium driver. The testing environment consists of: Linux (Ubuntu 12.10) RoR 3.1 Rsp ...

Tips for revealing a position: absolute div that is currently hidden with display: none styling

Below is the code for a div element that I want to temporarily hide using JavaScript: <div id="mydiv" style="position: absolute; top: 60px; left:5px; right:25px; bottom:10px;"> </div> After hiding it with display:none in my ...

Selenium Robot: Inconsistent Window Shuffling

Whenever I click on the "More Information" element, the link gets clicked, but then the window goes back to its previous state and a TimeoutException is displayed. Here is the code snippet: self.driver.window_handles base = "https://outlook.offic ...

Why does this code snippet throw an error if let is not hoisted or in the temporal dead zone? It could have simply used the global reference instead

var b = 6; { console.log(b) let b = 55 } When running this code snippet, I encounter the following error message: ReferenceError: Cannot access 'b' before initialization Why is the console.log(b) not displaying 6 as expected? ...

What is the method for including a data attribute in the text of a cell using Datatables Editor?

When initializing datatables along with editor, I typically use the following code: columns: [ { data: "name", className: 'noEdit clickTextToOpenModal' }, In this line of code, I am able to set the className attribute. However, is i ...

What could be the reason for a querySelector returning null in a Nextjs/React application even after the document has been fully loaded?

I am currently utilizing the Observer API to track changes. My objective is to locate the div element with the id of plTable, but it keeps returning as null. I initially suspected that this was due to the fact that the document had not finished loading, ...

Opening a Material UI dialog results in a change in the style of other components

Whenever I open the Dialog component from a button on the AppBar component, the margin on my navbar elements changes unexpectedly. I have checked the HTML using dev tools and there are no CSS changes on either of the components. Any suggestions on how to p ...

Guide to initializing modules in Angular 2+ using server-side responses

I used to initialize my Angular JS application by making a server call to fetch the user's access modules. I'm struggling to do the same in Angular 2+. Here is an example using AngularJS I only used ngMockE2E for demonstration purposes. (fu ...

Detecting When an Input has an :invalid Selector in Jquery

Here is the code snippet I am currently working with: HTML <input type="text" data-value="1" data-type="input-records" placeholder="Value" pattern="\d{1,4}$" /> CSS input[type=text]:invalid { background-color: red; } Javascript $("[data-ty ...

What causes offsetHeight to be less than clientHeight?

INFORMATION: clientHeight: Retrieves the height of an element, taking into account padding offsetHeight: Obtains the height of an element, considering padding, border, and scrollbar Analyzing the Data: The value returned by offsetHeight is expected to ...

Tap on the hyperlink using Selenium

I have a Selenium element with href="/daVinci/sys/systems/SK419114/dvmt https://i.sstatic.net/k3Rfu.png I am attempting to click on it for further navigation, the line of code I'm using is: driver.find_element_by_link_texrt(" ").click ...

Deliver a prompt reply from an external asynchronous function

Is there a way to send a response from a function that operates asynchronously outside of the express route? In my scenario, the function is designed to listen for events from SocketIO. How can I achieve sending a response from this function? setTimeout ...

Which architectural style is best to master for developing exceptional JavaScript software?

My familiarity with Model-View-Controller runs deep, having worked with it for years in server-side development using languages like PHP. Now, I find myself diving into JavaScript and embarking on a large project that utilizes SVG, Canvas, and other moder ...

Limiting an HTML table from scrolling in a single direction on an iPad

I have a simple HTML table with restricted width and height to enable vertical and horizontal scrolling. However, on iPad, users can scroll in all directions, including diagonally. I would like to limit the scrolling to one direction at a time. Can this be ...