Get time and date using cron expression in golang

0

i'm currently looking for a solution for sometimes now, i have this cron expression

time := '0 3,10,16,22 * * ?'

and i need to parse this into date and compare it to get a result

what my goal is to get time data from the time var and compare it, if the time is not in between 00:00 and 00:06 it will return bool false

i understand for comparison i can use if clause but,

how to parse this cron expression and turn it into date solution were not found yet. i've been reading cron package in godoc for sometimes and dont find it yet maybe i'm missing something?

any kind of solution or input were appreciated thanks!

cron go time
2021-11-24 06:53:39
1

0

You could use the package cronexpr from aptible/supercronic:

import "github.com/aptible/supercronic/cronexpr"
import "time"

nextTime := cronexpr.MustParse("0 3,10,16,22 * * ?").Next(time.Now())

Now that you have the next time, you can check if it is between 00:00 and 00:06.

2021-11-24 07:09:23

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................