currentTimestamp().convertToReadableFormat()

It feels like I'm spending too much time on this.

I've been trying to format the momento().toDate() in pt format but no luck so far.

I've already added it to my react code

import 'moment/locale/pt';
import moment from 'moment';

moment.locale('pt');

console.log(moment(date, 'DD-MM-YYYY').toDate());

However, the result I'm getting is Wed Feb 26 2020 00:00:00 GMT+0000 and not Qua Fev 2020 00:00:00 GMT+0000

Answer №1

My suggestion would be to transition away from Moment.js which is no longer actively maintained. Take a look at Day.js as an alternative. You can also refer to this helpful guide on how to change locales in Day.js via the following link.

Answer №2

As stated in the documentation, the toDate method returns a JavaScript Date object without considering the locale set in moment;

If you wish to obtain a formatted localized date, you can follow these steps:

moment.locale('pt');
moment(new Date()).format('MMMM');

Below is an example:

moment.locale('pt');
const result = moment(new Date()).format('MMMM');

console.log(result);
<script src="https://momentjs.com/downloads/moment-with-locales.js"></script>

However, as @Jibin Bose pointed out, moment.js is currently not actively maintained and it might be worth exploring other libraries like date-fns instead.

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

Resizing the Three.js canvas without impacting the renderer size or content scaling: A guide

I am currently in the process of creating a website using a Three.js canvas that covers the entire viewport. My goal is to keep the visuals consistent even when resizing the window, without any scaling. Here is my current approach: renderer.setSize(wind ...

(Discord.JS) Bot failing to send direct message upon user joining the server

When attempting to send a DM message, I am using the following code: bot.on('guildMemberAdd', (member) => { member.send('a'); }); I am experiencing difficulty in understanding why the private message is not being successfully se ...

The innerHTML of null cannot be set in Vue JS

I am attempting to showcase my array and its modifications after applying various methods <template> <div> <div id="example"></div> <div id="example1"></div> </div> </template> <s ...

Fade in and out of div elements upon clicking on an # anchor

I have been attempting to create a function where different divs fade in and out when clicking on an image with an <a href>. Unfortunately, I have not been successful in getting it to work despite several attempts. Here is the code that I am using: ...

Filtering Results Efficiently Based on Various Criteria in React

To view my project in action, please visit my sandbox here. Due to limitations, I am unable to paste all of the code directly here. The goal of my project is to create a tours filtration system based on multiple criteria. Each tour is represented as an ob ...

Using Zombie.js to simulate clicking on a Javascript link

I am currently using Node.js in combination with Zombie.js for web scraping. There are certain pages on which I need to interact with JavaScript links. For instance, consider the following page: http://www.indotrading.com/company/berkat-jaya-electronics. ...

The validation functionality in AngularJS for a form within an ng-repeat loop is not functioning as intended

In my table, I used the <tr> tag repeatedly with ng-repeat="cancellationPercentData in cancellationPercent" Each tr tag contains a form with name and id set using $index See the code snippet below: <tbody> <tr ng-repeat="cancellatio ...

PHP redirection cannot be directly translated to JavaScript redirection

I'm having an issue with my PHP file redirecting to an HTML file. The structure of my website is as follows: HTML ==> separate JS file (using Angular) ===> PHP file When the PHP file calls the header function, instead of redirecting, it displ ...

Changing the background color of MUI TextField for autocomplete suggestions

I am currently facing an issue with the background color of auto-complete fields in my React.js and Material UI app. https://i.sstatic.net/lZdDh.png The auto-complete fields are adding a white background which is unnecessary. Interestingly, when I manua ...

Can anyone offer any suggestions for this issue with Angular? I've tried following a Mosh tutorial but it's

Just finished watching a video at around 1 hour and 35 minutes mark where they added the courses part. However, I encountered an error during compilation. ../src/app/app.component.html:2:1 - error NG8001: 'courses' is not recognized as an elemen ...

JS: Submitting form data through POST method but fetching it with GET method?

When using PHP to retrieve data, the $_POST method cannot be used; only $_GET. Why is that? Could it be that I am not sending my form data correctly? I assumed that by using request.open("POST"), the form would be processed as a POST request rather than a ...

I came across a forum where someone mentioned encountering a similar issue but unfortunately, no solution was provided. Currently, I am working on setting up a reaction roles system but despite embedding the message, the role is not being

I am currently working on setting up a reaction roles system for my Discord server, but I have encountered a significant issue that may seem minor to most. The problem is that although my bot successfully sends embeds with corresponding emojis for the ro ...

Dynamic banner featuring animated text, automatically resizing divs based on width while maintaining body width

Currently, I am working on creating a banner with moving text. While I have managed to come up with a solution for implementing this effect, there are two significant issues that I am facing. The width values in pixels need to be manually adjusted based ...

Is it not possible to perform multiple queries using values stored in an array?

Essentially, I need the ability for my users to input various SKUs and UPCs (comma-separated) into a search field. From there, I want to generate an array of search values and run through an iterative process to return specific results or logic for each va ...

Trouble with React Material-UI Select component onChange event

I encountered an issue while using Material-UI select where I am unable to access the selected value due to a warning message: index.js:1 Warning: findDOMNode is deprecated in StrictMode. findDOMNode was passed an instance of Transition which is inside S ...

When incorporating conditional statements into your code, make sure to utilize the tags <script> along with

I have some script tags as shown below: <script src="cordova-2.5.0.js"></script> <script src="js/jquery-1.7.2.min.js"></script> <script src="js/jquery.mobile-1.1.1.min.js"></script> <script src="js/jquery.xdomainajax ...

Stopping halfway through a jQuery toggle width animation to close again

Perhaps the question may be a bit unclear, but allow me to provide an example. When repeatedly clicking the button that toggles the width, the div continues to animate long after the button press, which is not visually appealing. My desired outcome is for ...

The AngularJS $http.post method mimicking a successful $.ajax request is causing a 401 UNAUTHORISED error

I have been working on rewriting a functional $.ajax server call to utilize AngularJS $http.put. However, the $http method returns a 401 unauthorized error. The original ajax call I am attempting to rewrite is structured like this: $.ajax({ url: domain ...

Get the current executing event in jQuery by detecting multiple jQuery events

When I have a series of jQuery events like this: $(selector).on('click keydown blur', function(){ //do something } Is there a way to determine which event triggered the function at the current time? For instance, consider the following sce ...

Adding a condition prior to inserting rows into a table using jQuery

Seeking advice on implementing an HTML template that includes a table and an add button. When the add button is clicked, selections are meant to be added to the table. The requirement is to introduce a condition where if one of the selections contains "Map ...