编辑代码

import java.text.SimpleDateFormat

def convertDateToTimestamp(String dateStr) {
    // 定义日期格式
    def dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
    try {
        // 解析日期字符串
        Date date = dateFormat.parse(dateStr)

        // 获取 Java 时间戳(毫秒)
        long javaTimestamp = date.time

        // 将 Java 时间戳转换为指定格式的时间戳
        long customTimestamp = javaTimestamp * 10000 + 621355968000000000
        return customTimestamp
    } catch (Exception e) {
        println "日期解析出错: ${e.message}"
        return null
    }
}

// 测试函数,这里需要替换 nowtime 为实际的日期字符串
def nowtime = "2025-04-22 12:00:00"
def result = convertDateToTimestamp(nowtime)
println result