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.
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
| FormInputType | Description |
|---|---|
DATE | Date picker |
TIME | Time picker |
DATETIME | Date and time picker |
Supported Types
The following JVM types are automatically detected.
| Kotlin / Java Type | Default Input |
|---|---|
LocalDate | DATE |
LocalTime | TIME |
LocalDateTime | DATETIME |
OffsetDateTime | DATETIME |
Instant | DATETIME |
java.util.Date | DATETIME |
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
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.
Audit fields such as createdAt and updatedAt are typically marked as read-only since they are managed automatically by the application.
Always store timestamps using a consistent timezone (typically UTC) and convert them for display when necessary.
Related Properties
| Property | Description |
|---|---|
label | Display label |
required | Makes the field mandatory |
placeholder | Input hint |
readonly | Prevents editing |
sortable | Enables table sorting |
showInTable | Controls table visibility |
group | Form section grouping |
validationMessage | Custom validation error |
See Also
- Number
- Text
- Select
- Checkbox
- Range