×

Ionic Date Time

Ionic Date Time

The DateTime component is used to display an interface that makes it simple for users to select dates and times. Tapping on <ion-datetime> will display a slider up from the bottom of the page. Next, the selector displays scrollable columns that can be used to individually specify values for years, months, days, hours, and minutes. The DateTime component is similar to the original <input type = "datetime-local"> element. However, the Ionic DateTime component makes it easy to display the date and time in a preferred format and manage the date and time values.

Example: This example shows how you can use the <ion-datetime> component.

 
   
  
  DateTime
   
   
  
  
    
   
  simple datetime 
   
   
   
   

Output: After executing this code, you will get the output, as shown below.

Ionic Date Time

When you click on the simple date time option, you will get the pop-up screen. It shows your current system date and time information. When you select date and time and to finalize it, you click on the Done button.

When you select date and time

Display and Picker Formats

The DateTime component shows values in two places. The first is in the <ion-datetime> component, and second in the interface provided at the bottom of the screen. The following table lists all the formats that can be used.

Display Format

The displayFormat input property determines how the date-time value, as formatted text, is printed within the <ion-datatime> component.

Picker Format

The pickerFormat input property specifies which columns to display in the interface, the column order, and the format to use in each column. If pickerFormat input is not provided, it will use the value of diasplayFormat.

Example: This example shows how you can add the displayFormat and pickerFormat attribute inside the <ion-datetime> component.

 
   
  DateTime 
   
   
   
   
    
  Start Time 
   
   
   
  Ends 
   
   
    
  Specific Format 
   
   
   
    

Output: After executing this code, you will get the output, as shown below.

Picker Format

When you click on the Specific Format option, you will get the pop-up screen. Here, you can choose your selective year and finalize it, and you click on the Done button.

click on the Specific Format option

Datetime Data

The handling of datetime values within JavaScript or HTML inputs has always been a challenge. Specifically, a JavaScript date object is known to be challenging to parse date and time strings correctly or to format date and time values. Worse, how different browsers and JavaScript versions of date and time strings are analyzed differently, especially by location. Ionic datetime input is designed so the developers can avoid the common pitfalls. It also permits developers to simple format datetime values within the input. It gives the user a simple datetime picker for an excellent user experience.

ISO 8601 Datetime Format

Ionic uses the ISO 8601 date and time format for its value. The value is just a string, instead of using a JavaScript date object. Also, when using the ISO date and time format, it is easier to serialize and pass within JSON objects, and send a uniform format to databases that can be easily analyzed, if necessary.

The ISO format can be used as a simple year, just an hour and a minute, or get more detail in milliseconds and time zones. Any of the ISO setups below can be used, and after the user selects a new value, Ionic will continue to use the same ISO format in which the date and time value is set. The following Datetime table shown below:

Description Format Datetime Value Example
Year YYYY 1998
Year and Month YYYY-MM 1997-15
Complete Date YYYY-MM-DD 1998-05-25
Date and Time YYYY-MM-DDTHH:mm 1997-04-21T12:26
UTC Timezone YYYY-MM-DDTHH:mm:ssTZD 1998-08-04T06:34:46.789Z
Timezone Offset YYYY-MM-DDTHH:mm:ssTZD 1994-05-16T13:45:52.789+5:00
Hour and Minute HH:mm 16:45
Hour, Minute, Second HH:mm:ss 14:55:22

Max and Min datetimes

Dates do not end in any direction, so there must be at least some ways to restrict the dates that can be selected for the user's choice. By default, the maximum date is at the end of the current year, and the minimum date is from the beginning of the year that was 100 years ago. To customize the minimum and maximum date and time values, you can provide the min and max component inputs, which may make more sense for the application's use case, rather than the default value of the last 100 years.

Example: This example shows the use of the disabled, minimum, and maximum attributes with the <ion-datetime> component.

 
   
  
  DateTime
   
   
   
   
   
    
  Disable Date 
   
   
   
  Max and Min 
   
    
   
    

Output: After executing this code, you will get the output, as shown below.

Max and Min datetimes

When you click on the Max and Min option, you will get the pop-up screen. Here, you can choose your particular datetime and finalize it, and you click on the Done button.

Max and Min option

Specific Date/ Month/Year

The <ion-datetime> component also lets you specify a particular date, months, and years by setting the monthValues, dateValues, and yearValues properties.

The following code shows how it can work with <ion-datetime> component.

Example:

 
   
  DateTime 
   
   
   
   
   
  Specific date/month/year 
    
   
   
   

Output: After executing this code, you will get the output, as shown below.

Specific Date MonthYear

Related Topics

Ionic Spinner

The ionic spinner component provides the various SVG (Scalable Vector Graphic) spinners. Ionic spinners are the visual indicators that display the app which is loading content or performing another process that the user...

5 minutes read.

Ionic Grid

The Ionic grid is a very powerful mobile-first flexbox system for building the custom layouts. It is a CSS feature supported by all devices that ionic supports. The Ionic grid is composed of...

11 minutes read.

Ionic Segment

A segment is a collection of buttons, sometimes which are known as segmented controls. The segment buttons are displayed at horizontal rows. These segment buttons can be shown in a toolbar or the...

2 minutes read.

Ionic Input

Ionic Input Inputs are necessary to collect and process user inputs securely. To be easy for users to communicate, they must follow the process and communication guidelines for each platform. It is a...

3 minutes read.

Ionic vs Apache Cordova

Ionic Vs Apache Cordova Ionic and Cordova are two popular technology going on in the market for mobile application development. The combination of these two technologies creates a development platform that is known as...

3 minutes read.

Ionic Geolocation

In today’s time, the mobile location plays an essential role in the mobile application. The Ionic Cordova geolocation plugin provides information about the location of the device, like as latitude and longitude. The...

5 minutes read.

Ionic vs React Native

Ionic Vs React Native Ionic and React Native are both common framework which is used to develop mobile applications. Here, you will know about the popular differences between the ionic and the React Native. Ionic Ionic...

3 minutes read.

Ionic Refresher

Refresher means updating the currently showing page so that the user can see the latest view. It is also known as re-loading in web technology. It provides a pull- to-refresh feature on a...

4 minutes read.

Ionic Editors

Editors are software programs that permit the users to create and edit the text files. In the development field, editors are usually used to create the source code editors that includes many specific...

3 minutes read.

Ionic vs PhoneGap

Ionic Vs PhoneGap Ionic and PhoneGap are both used to develop the mobile application. Both Frameworks are used in large enterprises by the developers. Here, we are going to compare the important differences between ionic...

3 minutes read.

Ionic Menu

The Ionic menu is the side-menu navigation that can be slide in from the side of the current view. By default, the menu slides in from the left side, but the side...

7 minutes read.

Ionic Popover

The Ionic popover is a small dialog box that displays at the top of the screen. It can be used for anything, but it is usually used for a button, an action,...

4 minutes read.

Difference between Ionic 4 and Ionic 3

The ionic framework is an open-source platform that is used to develop mobile applications. It is also used to build android applications, desktop applications, iOS, and web applications using web technologies like HTML,...

5 minutes read.

Ionic Radio

Ionic Radio The radio button is the type of input component that has a Boolean value. The Ionic radio button has a different pattern on every platform, as well as other Ionic components....

2 minutes read.

Ionic Loading

The ionic loader is an overlay that can be used to indicate activity, the user interaction while blocking. The ionic loader shows on the top of the app content, and it can...

5 minutes read.

Ionic Splash Screen

The Apache Cordova plugin helps to displays and hides a splash screen during the application launch. The Ionic Splash Screen is similar to a home page on a website. The ionic splash...

2 minutes read.

Ionic Camera

Hybrid mobile applications can make very quickly, but sometimes it becomes a challenge to get the features that access the hardware such as GPS, storage, file storage, cameras, and networks. Cordova offers plugins...

4 minutes read.

Ionic Range

The Range slider lets users choose from a range of values by moving the slider knob. You can accept two knobs, but by default, one-knob controls the range value. Range labels You can put down on...

2 minutes read.

Ionic Toggle

The toggle is the same as the HTML checkbox entry, but it looks different and easier to use on a touchscreen device. It is an input component that holds the boolean value. Toggle...

2 minutes read.

Ionic Tabs

The ionic tabs mostly used for mobile navigation. It means that tabs are placed at the top of the display on android devices, while at the bottom on IOS. It does not provide...

2 minutes read.