Added dateToGmt() function.
This commit is contained in:
parent
c7eb6518ac
commit
4b018f926a
2 changed files with 36 additions and 0 deletions
|
@ -39,6 +39,10 @@ import okhttp3.OkHttpClient
|
|||
import okhttp3.Request
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import java.io.IOException
|
||||
import java.time.LocalDateTime
|
||||
import java.time.ZoneId
|
||||
import java.time.ZoneOffset
|
||||
import java.util.Date
|
||||
import java.util.logging.Level
|
||||
import java.util.logging.Logger
|
||||
import javax.servlet.http.HttpServletRequest
|
||||
|
@ -423,6 +427,21 @@ open class Akismet(apiKey: String, blog: String) {
|
|||
other = other))
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a [Date][java.util.Date] to a UTC timestamp (xxxGmt parameters).
|
||||
*/
|
||||
@JvmOverloads
|
||||
fun dateToGmt(date: Date, zoneId: ZoneId = ZoneId.systemDefault()): String {
|
||||
return dateToGmt(LocalDateTime.ofInstant(date.toInstant(), zoneId))
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a [LocalDateTime][java.time.LocalDateTime] to a UTC timestamp (xxxGmt parameters).
|
||||
*/
|
||||
fun dateToGmt(date: LocalDateTime): String {
|
||||
return date.atZone(ZoneOffset.UTC)?.toEpochSecond().toString()
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* Execute an Akismet REST API method.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue