If you want to do this in Groovy - you need to convert the string to Long like:
def before = vars.get('beforetime') as long
def current = vars.get('CurrentTime1') as long
def delta = current - before
def deltaAsString = delta as String
If you prefer using JMeter Functions - you can go for __longSum()
${__longSum(${CurrentTime1},-${beforetime},)}
More information on this and other JMeter Functions: How to Use JMeter Functions - Part III
But don't mix both approaches like inlining JMeter functions in Groovy code, as per JSR223 Sampler documentation:
When using this feature, ensure your script code does not use JMeter variables or JMeter function calls directly in script code as caching would only cache first replacement. Instead use script parameters.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…