Converting datetime to time format

I have a datetime column in the format of YYYY-MM-DD HH:mm:ss.SSS. Is there a way to display only the time in the format of HH:mm:ss.SSS without showing the complete datetime?

I have attempted the following code, but it does not seem to affect the format:

{name: 'somedate', field: 'event_date', cellFilter: 'date:\'HH:MM:SS.SSS\''}

UPDATE

This is how the grid is set up:

$scope.gridOptions = {
    columnDefs: [{name: 'somedata', field: 'event_date'}],
    data: [ {event_date: "2016-03-10 10:10:11.123"}]
}

Answer №1

If you're working with Angular and need to display the time part of a date, it's as easy as using | date: 'HH:mm:ss':

HTML

  <span>{{1288323623006 | date: 'HH:mm:ss'}}</span>

The value 1288323623006 represents the date value field; you can swap it out with your own field name in your code.

Alternatively, you can achieve the same result in your controller by injecting $filter:

var formattedDate = $filter('date')(1288323623006, 'HH:mm:ss');

Here's a complete example:

angular.module('dateFormat', [])
   .controller('ExampleController', ['$scope','$filter', function($scope,$filter) {

     $scope.formattedDate = $filter('date')(1288323623006, 'HH:mm:ss');

   }]);

Answer №2

Pay attention to the format. Ensure it is HH:mm:ss.sss

Answer №3

To update your cell filter, simply modify it as shown below:

cellFilter: 'date:\' HH:mm:ss\'' 

Answer №4

Alternatively, you have the option to modify it directly within the columnDefs like so:

cellTemplate: "<div>{{grid.getCellValue(row,col) | date:'MM/dd/yyyy'}}</div>"

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 <a> tag does not lead to a different webpage and cannot be clicked on

I have developed a web component that includes a method to generate a copyright string: '<p>Copyright © 2020 John Doe<a href="https://www.example.com">. Terms of Use</a></p>' After creating the string, I conver ...

Knockout JS: Choosing specific dropdown elements

My array doorsForSite contains a list of doors, each with its own set of schedules. Here is how it looks: var scheduleList = new[] { new { ScheduleId = "Schedule1",ScheduleName = "Always On" }, new ...

An issue occurred with the DOMException while trying to execute the 'setAttribute' function on the 'Element': '{{' is an invalid attribute identifier

Currently, the code is under development and some methods are still empty while the *ngIf directives may not be correct in terms of logic. However, even with these issues, I encountered the same error without bothering to remove them at this stage. While ...

What is the best way to conceal a canvas or another item?

Within my main canvas, there are three smaller canvases and a text element. <canvas id="Background" width="350" height="300" style="border:6px solid black; position: absolute; left: 10px; top: 10px;"> </canvas> <canvas id="Canvas1" width ...

Custom Sign-in features in NextJS now direct users to the default form for entering login

I have been working on a web app that requires authentication using NextJS default auth middleware. However, whenever I try to log in, the app redirects me to the default NextJS form component at the URL /api/auth/signin?error=CredentialsSignin. Even thou ...

How to display only a portion of content using UI Bootstrap collapse feature

In my Angular.js application, I currently have a row of buttons that open up new routes to display partial views. Now, I need to modify some of these buttons to trigger a ui.bootstrap Collapse feature with the view inside it. The template code from the ui. ...

Utilizing Jquery and Ajax to create a dynamic dropdown selection feature based on dependencies from a JSON file

Could you assist with the code snippet below? I have a form where each dropdown list depends on the selection above it. Based on the user's selection, the appropriate data should display in the subsequent dropdown list. I am trying to make dropdown l ...

Combining Jquery with Append to Dynamically Update PHP Variables

Code Snippet (index.html) <script> $(document).ready(function() { var interval = setInterval(function() { $.get("load_txt.php", { 'var1': 4, 'var2' : 52}, function(data){ $('#msg' ...

The values are not being properly initialized in the componentDidMount() function

I've been refactoring my code lately and experimenting with using all the lifecycle methods available to me. In an attempt to initialize the state of a component using componentDidMount(), I've encountered some issues. Previously, I used this.pro ...

What is the best way to showcase an item from an array using a timer?

I'm currently working on a music app and I have a specific requirement to showcase content from an array object based on a start and duration time. Here's a sample of the data structure: [ { id: 1, content: 'hello how are you', start: 0 ...

Enhance the original array of a recursive treeview in VueJS

After going through this tutorial, I decided to create my own tree view using recursive components in Vue.js. The structure of the input array is as follows: let tree = { label: 'root', nodes: [ { label: 'item1', nod ...

Uncertainty arises from the information transmitted from the controller to the Ajax function

In one of my coffee scripts, I have an AJAX call that calls a method in a controller. The AJAX call is structured like this: auto = -> $.ajax url : '<method_name>' type : 'POST' data : <variable_name> ...

What is the method for inserting an icon using createElement?

Can someone help me figure out how to create a Material-UI icon using JavaScript? I am currently using the Material-UI-icon library. import ThumbUpIcon from '@material-ui/icons/ThumbUp'; var thumbsup = document.createElement(ThumbUpIcon); Any ...

Determine the number of rows in an Ajax-fed datatable (including paginated rows) that have a specific value in a

I am struggling with counting rows in #datatableOne where the 'Status' column has a value of 'Unknown'. I have attempted a couple of solutions, but they are not giving me the desired results. The first solution only counts the rows on ...

Showing RSS feed on Vue.js interface

I am trying to integrate a Google Alert feed into my Vue.js application, specifically on the "Dashboard.vue" component using "Feed.vue". I have successfully implemented this feature in JavaScript, but I am facing difficulties converting it to Vue.js. Curr ...

Having Trouble with QR Code Generator Functionality

UPDATE: The initial code has been updated to implement the recommendations provided. I am currently working on a QR Code generator that updates every minute. Although I have developed the code below, I am encountering some errors and could use some assist ...

Avoid activating jQuery functions based on certain screen widths for menu/navigation system

Recently, I've delved into the world of jQuery and attempted to create a simple menu system. The menu is designed to expand its submenu when hovering over the list item at screen widths larger than 480px, and to expand when clicking on the list item a ...

Is there a translation issue affecting Chrome version 44?

Recently, Chrome 44 (44.0.2403.89 m) was released and I've encountered some issues with the translate3d feature (on both Mac and Windows versions). This problem is impacting plugins such as fullPage.js and consequently affecting numerous pages at th ...

The element vanishes from sight after being detached and re-appended

Currently, I am utilizing hQuery's draggable and droppable features. My goal is to move an element from its original parent to its new dropped parent after dragging it. However, when I detach and append the element, it seems to disappear! What could ...

Turn on / off Button Using a Different Button

I am currently working on an application that is designed to create teams using button selectors. There are two initial teams in play: the (available team) which consists of two buttons - one for selecting a player and populating the player name into the ( ...