节点在线、应用在线、配置在线使用令牌查询
大石头 authored at 2021-12-16 19:49:30
581.00 B
Stardust
//go:build windows

package command

import (
	"context"
	"fmt"
	"os/exec"
	"strings"
	"time"
)

func defaultSyncTime(target time.Time) error {
	ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
	defer cancel()

	script := fmt.Sprintf("Set-Date -Date '%s'", target.UTC().Format(time.RFC3339))
	cmd := exec.CommandContext(ctx, "powershell", "-NoProfile", "-NonInteractive", "-Command", script)
	output, err := cmd.CombinedOutput()
	if err != nil {
		return fmt.Errorf("Set-Date 执行失败: %w: %s", err, strings.TrimSpace(string(output)))
	}

	return nil
}