Getting date in local time in plugin

I want to make a plugin that converts a human date and time format to an Epoch timestamp. I’m caught up because I want to make the date be inputted in the user’s local time but still give an accurate Unix timestamp.

Here’s my code:

local month, day, year = string.match(dateDisplay.Text, "(%d%d)/(%d%d)/(%d%d%d%d)")
local hour, min, sec = string.match(timeDisplay.Text, "(%d%d):(%d%d):(%d%d)")	
if not (day and month and year and hour and min and sec) then return end
	
day, month, year = tonumber(day), tonumber(month), tonumber(year)
hour, min, sec = tonumber(hour), tonumber(min), tonumber(sec)
if not (day and month and year and hour and min and sec) then return end
	
if day > 31 or month > 12 or hour > 23 or min > 59 or sec > 59 then return end

local dateTable = {
	year = year,
	month = month,
	day = day,
	hour = hour,
	min = min,
	sec = sec,
}

-- not sure what to do after this

Everything I have tried so far has been giving me the wrong time because the input expects the time to be inputted in UTC, when I want to input it in my local time (BST). When I input 08:00:00 into it, it’s actually giving me the timestamp for 09:00:00 BST because it is misinterpreting the 08:00:00 as the actual UTC time.

Thanks in advance :slightly_smiling_face:

Have you tried using DateTime? i.e.

DateTime.fromLocalTime(year, month, day, hour, min, sec).UnixTimestamp

This will create a DateTime instance based in the user’s local timezone and get its Unix timestamp in UTC