Angular.js has a unique filter that allows users to customize the date format to their preference

My upcoming event is happening on

"endDate": "2014-11-30 01:00:00.0",
in JSON format. I want to display it as 30 Nov 2014.

I attempted to display it using:

{{ phone.endDate  | date:'medium' }}

within an HTML document.

Unfortunately, it is still showing as 2014-11-30 01:00:00.0.

Answer №1

To avoid converting your string to a date in the controller, consider creating a custom filter:

app.filter('customDateFilter', ['$filter', function($filter) {
  return function(dateString) {
     var convertedDate = new Date(dateString);
     return $filter('date')(convertedDate, 'dd MMM yyyy');
  }
}]);

Answer №2

For easy date and time manipulation, consider using Moment.js:

$scope.currentTime = moment(new Date()).format('DD MMM YYYY');

Answer №3

After referencing the answer above, I managed to find a solution and implement the following code:

phonecatApp.filter('myDateFilter', ['$filter', function($filter) {
  return function(date) {
    // console.log(date);
    var VendDate = date.split(" ");
    // console.log(VendDate);
    var endDate = VendDate[0].split("-");
    // console.log(endDate);
    var convertedDate = new Date(endDate[0], endDate[1], endDate[2]);
    return $filter('date')(convertedDate, 'dd MMM yyyy');
  }
}]);

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

Is there a way to make the switch case condition shorter?

I need to dynamically select a text input field based on the variable type chosen, without having to include the textfield component in every single condition. const chooseInputType = () => { switch (type) { case 'boolean': ...

How can I retrieve the parent scope in an Angular UI nested named view?

One of the challenges I faced in my application was dealing with nested views within several screens. After experimenting with different approaches, I discovered that creating modal dialog boxes and sliding panels as actual nested states with corresponding ...

Obtain an Element Using Puppeteer

Currently grappling with a sensitive issue concerning puppeteer. The HTML structure in question is as follows: <tbody> <tr rel="0" class="disabled" id="user6335934" class="odd"> ...

"Exploring the world of server-side and client-side MVC frameworks

I recently embarked on learning ASP.Net MVC and have encountered some puzzling questions regarding the MVC framework - particularly, whether it leans more towards client-side or server-side operation. I understand if these queries seem basic, but I'd ...

Implementing a loop in JSON with Angular: A step-by-step guide

I have a task to generate a JSON structure that looks like the following: "combinationsData":[ { "combinationName":"2_2", "dataGroups": [ { "tableType":"2",//This value comes from HTML "twoAxisDat ...

Angular 2: Enhancing Textareas with Emoji Insertion

I am looking to incorporate emojis into my text messages. <textarea class="msgarea" * [(ngModel)]="msg" name="message-to-send" id="message-to-send" placeholder="Type your message" rows="3"></textarea> After entering the text, I want the emoj ...

Use a JavaScript function on identical IDs

Can someone please help me figure out how to hide multiple divs with the same id using JavaScript? I attempted the following: <script> function filterfunc() { if(document.getElementById('filter_deductible').value == 'id_50'){ ...

"Problems arise with mongodb full $text search when sorting and filtering, causing duplicate items to

When using full-text search in my API and sorting by score, I am encountering an issue where the same item is returned multiple times. This behavior is not what I expected. How can I correct this to ensure unique results? Below is the structure of my rout ...

Struggling to implement Google OAuth in a MERN stack - facing a 400 bad request error with the package @react-oauth/google

Here is the React form and relevant code sections for the issue: import { useGoogleLogin } from '@react-oauth/google'; const SignUpForm = () => { const navigate = useNavigate(); const [name, setName] = useState(""); const [email, setEm ...

React App searching for unused static files

Currently, my React application is deployed on the Nginx web server. Accessing the application using the URL XX.XX.XX.XX works fine. However, I want to be able to access it through the URL XX.XX.XX.XX/myapp/frontend. To achieve this, I have set up a revers ...

Issue with CORS on Next.js static files leading to broken links on version 10.1.4

Currently, my Nextjs application is fetching its static files from Cloudfront. During deployment, I upload the /static folder to S3. After updating to version 9, I encountered a strange problem where some of my CSS files are triggering a CORS error: Acces ...

Leveraging $compile within a directive

My directive is designed to only execute when the $compile.debugInfoEnabled() method returns true. The issue I am facing is that the $compile object is showing up as undefined: angular .module('myapp', []) .directive('myDebugThing& ...

Do not directly change a prop - VueJS Datatable

Just starting out on Vue JS and encountered an issue while trying to create a Data Table by passing parent props to child components. An Error Occurred: [Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the parent ...

The Ajax call failed to connect with the matching JSON file

<!DOCTYPE html> <html> <body> <p id="demo"></p> <script <script> function launch_program(){ var xml=new XMLHttpRequest(); var url="student.json"; xml.open("GET", url, true); xml.send(); xml.onreadystatechange=fun ...

Tips for sending a JavaScript object from PHP to AJAX

I've been racking my brain for hours, scouring through countless articles, but I'm still unable to crack this puzzle. Here's the situation: I'm currently tinkering with Chrome extensions and I need to make a server call that will fetch ...

Selenium webdriver cannot find the element within the JavaScript code

await driver.findElement(By.id('closeBtn')).click(); or await driver.findElement(By.xpath('//*[@id="closeBtn"]')).click(); When attempting to use the above conditions for a pop-up, it does not work as expected. An error is ...

What is the most effective method for grouping state updates from asynchronous calls in React for efficiency?

After reading this informative post, I learned that React does not automatically batch state updates when dealing with non-react events like setTimeout and Promise calls. Unlike react-based events such as onClick events, which are batched by react to reduc ...

I'm encountering issues with this code for a dice game. It's strange that whenever I click the roll dice button, it disappears. Additionally, linking an .css sheet seems to cause the entire page to

I'm currently working with two separate codes: one for HTML and the other for JavaScript. I am facing an issue where the button keeps disappearing when I try to add any CSS styling to it. Even a basic CSS file seems to override everything else and lea ...

Monitoring changes within a factory

Hey there! I've got this shared_service factory that's being used by my menu and other elements on the page. angular.module('shared_service', []). factory('Shared', function($scope){ var shared_service = { ...

AngularJS is unable to properly show the full calendar on the screen

Currently working with fullcalender.js in conjunction with AngularJS. Encountering an issue where the calendar is not displaying without any error indication, making it difficult to identify the missing component. This marks my initial attempt at combinin ...