datetimehelper.sh 563 Bytes
function todate() {
    [[ $# -eq 0 ]] && return 1
    date -d ${1} +%d.%m.%Y
}

function tstodate() {
    [[ $# -eq 0 ]] && return 1
    date -d @${1} +%Y-%m-%d
}

function extracttime() {
    local OIFS=${IFS}

    if [[ $# -eq 0 || -z $1 ]]
    then
        TIMEKEY=""
        TIME="00:00:00"
    else
        IFS=:
        set -- $=1
        IFS=${OIFS}
        TIMEKEY=$1
        TIME=$(printf "%02d:%02d:%02d" ${2:-0} ${3:-0} $4)
    fi
}

function formattime() {
    local DAYS=${1%%:*}
    printf "%03dd %s" ${DAYS:-0} ${1#*:}
}

# vim: set et ts=4 sw=4: