{"id":9343,"date":"2024-01-19T10:47:14","date_gmt":"2024-01-19T10:47:14","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/qanda\/?p=9343"},"modified":"2024-01-19T10:47:14","modified_gmt":"2024-01-19T10:47:14","slug":"get-the-current-date-in-react-native","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/qanda\/react-native\/get-the-current-date-in-react-native","title":{"rendered":"How to Get the Current Date in React Native?"},"content":{"rendered":"<p>No need for external libraries, as React Native fully supports JavaScript&#8217;s Date functionalities. Simply create a new Date object to capture the current date and time:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"ruby\">\r\nlet currentDate = new Date();\r\nconsole.log(currentDate);<\/pre>\n<p>Customize further by specifying options like language and time zone:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"ruby\">\r\nlet currentDate = new Date();\r\nconsole.log(currentDate.toLocaleDateString()); \/\/ prints date in the format: \"MM\/DD\/YYYY\"\r\nconsole.log(currentDate.toLocaleTimeString()); \/\/ prints time in the format: \"HH:MM:SS AM\/PM\"\r\n<\/pre>\n<p>When dealing with intricate date calculations or crafting custom date displays, you might find libraries like moment.js and date-fns useful companions.<\/p>\n<p>Here&#8217;s how you can get the current date with moment.js:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"ruby\">\r\nimport moment from 'moment';\r\n\r\nlet currentDate = moment().format('YYYY-MM-DD');\r\nconsole.log(currentDate);\r\n<\/pre>\n<p>For projects prioritizing efficiency, day.js stands out as a compelling alternative to moment.js. While sharing similar functionality, its reduced footprint makes it a top contender for performance-hungry environments.<\/p>\n<p>Here&#8217;s how you can get the current date with day.js:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"ruby\">\r\nimport dayjs from 'dayjs';\r\n\r\nlet currentDate = dayjs().format('YYYY-MM-DD');\r\nconsole.log(currentDate);\r\n<\/pre>\n<p>For simple date tasks, the built-in Date object is good enough. But in larger projects, where date acrobatics and fancy formatting are needed, libraries like moment.js and date-fns come to the rescue. And for those extra concerned about app size and speed, day.js is gaining a lot of love for being small and similar to moment.js. Think of it as the lightweight, high-performance option for your date with code!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>No need for external libraries, as React Native fully supports JavaScript&#8217;s Date functionalities. Simply create a new Date object to capture the current date and time: let currentDate = new Date(); console.log(currentDate); Customize further by specifying options like language and time zone: let currentDate = new Date(); console.log(currentDate.toLocaleDateString()); \/\/ prints date in the format: &#8220;MM\/DD\/YYYY&#8221; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":9346,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[14],"tags":[],"class_list":["post-9343","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-react-native"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/9343"}],"collection":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/comments?post=9343"}],"version-history":[{"count":2,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/9343\/revisions"}],"predecessor-version":[{"id":9348,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/9343\/revisions\/9348"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media\/9346"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media?parent=9343"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/categories?post=9343"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/tags?post=9343"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}