All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.chestmc.common.extensions.Times.kt Maven / Gradle / Ivy

package net.chestmc.common.extensions

import org.joda.time.DateTime
import org.joda.time.LocalDate
import org.joda.time.LocalDateTime
import java.text.DateFormat
import java.text.SimpleDateFormat
import java.util.*

/**
 * The default date format used.
 */
val DEFAULT_DATE_FORMAT = SimpleDateFormat("HH:mm:ss dd/MM/yyyy")

/**
 * Returns the current time millis.
 */
inline val currentMillis get() = System.currentTimeMillis()

/**
 * Gets the actual date, this is, the current date.
 */
fun actualDate(): Date = Date()

/**
 * Converts this date to a local date.
 */
fun Date.toLocalDate(): LocalDate = LocalDate(time)

/**
 * Converts this date to a date time.
 */
fun Date.toDateTime(): DateTime = DateTime(time)

/**
 * Converts this date to a local date.
 */
fun Date.toLocalDateTime(): LocalDateTime = LocalDateTime(time)

/**
 * Formats this date by the specifed date format.
 */
fun Date.format(format: DateFormat = DEFAULT_DATE_FORMAT): String = format.format(this)

/**
 * Converts this string to a date by the specified date format.
 */
fun String.toDate(format: DateFormat = DEFAULT_DATE_FORMAT): Date = format.parse(this)




© 2015 - 2025 Weber Informatics LLC | Privacy Policy