Date & Time

The Date & Time field types allow administrators to select dates, times, or complete timestamps using native browser controls.

KraftAdmin automatically detects common Java and Kotlin date/time types and renders the appropriate input component.

ℹ️ Info

In most cases you do not need to specify an input type. KraftAdmin infers the correct component from the property’s type.

Available Input Types

FormInputTypeDescription
DATEDate picker
TIMETime picker
DATETIMEDate and time picker

Supported Types

The following JVM types are automatically detected.

Kotlin / Java TypeDefault Input
LocalDateDATE
LocalTimeTIME
LocalDateTimeDATETIME
OffsetDateTimeDATETIME
InstantDATETIME
java.util.DateDATETIME

Automatic Detection

@Entity
class Event(

    var eventDate: LocalDate,

    var startTime: LocalTime,

    var createdAt: LocalDateTime
)

KraftAdmin automatically generates the appropriate date and time pickers.


Explicit Configuration

You can explicitly specify the desired input type.

@KraftAdminField(
    label = "Start Date",
    inputType = FormInputType.DATE
)
var startDate: LocalDate? = null

Date & Time

@KraftAdminField(
    label = "Published At",
    inputType = FormInputType.DATETIME
)
var publishedAt: LocalDateTime? = null

Time Only

@KraftAdminField(
    label = "Opening Time",
    inputType = FormInputType.TIME
)
var openingTime: LocalTime? = null

Required Field

@KraftAdminField(
    required = true,
    validationMessage = "Please select a date."
)
var eventDate: LocalDate? = null

Placeholder

Some browsers ignore placeholders for native date controls.

@KraftAdminField(
    placeholder = "Select a date"
)
var eventDate: LocalDate? = null

Read-only

@KraftAdminField(
    readonly = true
)
var createdAt: LocalDateTime? = null

The value is visible but cannot be modified.


Hide from Tables

@KraftAdminField(
    showInTable = false
)
var lastModified: LocalDateTime? = null

Useful for audit timestamps.


Sorting

Date fields are sortable by default.

@KraftAdminField(
    sortable = false
)
var scheduledAt: LocalDateTime? = null

Grouping

@KraftAdminField(
    group = "Scheduling"
)
var eventDate: LocalDate? = null

Best Practices

💡 Tip

Use the Java Time API (LocalDate, LocalTime, and LocalDateTime) instead of legacy java.util.Date whenever possible. These types are immutable, timezone-aware where appropriate, and provide better interoperability with modern Spring Boot applications.

ℹ️ Info

Audit fields such as createdAt and updatedAt are typically marked as read-only since they are managed automatically by the application.

⚠️ Warning

Always store timestamps using a consistent timezone (typically UTC) and convert them for display when necessary.


Related Properties

PropertyDescription
labelDisplay label
requiredMakes the field mandatory
placeholderInput hint
readonlyPrevents editing
sortableEnables table sorting
showInTableControls table visibility
groupForm section grouping
validationMessageCustom validation error

See Also

  • Number
  • Text
  • Select
  • Checkbox
  • Range