Q=cp * d * V * (Tf - Ti)
joules of heat transferred = isobaric specific heat capacity measured in joules per gram Kelvin difference * density measured in grams per cubic metre * volume in litres * (final temp - initial temp in centigrade)
isobaric specific heat capacity of water = 4.18 joules per gram Kelvin difference
density of water = 1 gram per cubic meter
For my 1643L spa, with incoming water temp of 6.5C, target temperature of 38C, this is 215,149 joules of heat transferred = 215.149 megajoules, divide by 3.6 for kWh = 59.764kWh.
For a 4kW heater, divide by 4 = 14.941 hours to transfer that heat assuming zero heat loss through cover/sides/plumbing. So consider your resulting number the absolute minimum amount of time to heat. At $0.22/kWh, electricity cost is $12.97, and at $1.58/cubic metre of water, water cost is $2.60.