Current deep learning models for time series often face challenges with generalizability in scenarios characterized by limited samples or inadequately labeled data. By tapping into the robust generative capabilities of diffusion models, which have shown success in computer vision and natural language processing, we see potential for improving the adaptability of deep learning models. However, the specific application of diffusion models in generating samples for time series classification tasks remains underexplored. To bridge this gap, we introduce the MDGPS model, which incorporates multi-task diffusion learning and gradient-free patch search (MDGPS). Our methodology aims to bolster the generalizability of time series classification models confronted with restricted labeled samples. The multi-task diffusion learning module integrates frequency-domain classification with random masked patches diffusion learning, leveraging frequency-domain feature representations and patch observation distributions to improve the discriminative properties of generated samples. Furthermore, a gradient-free patch search module, utilizing the particle swarm optimization algorithm, refines time series for specific samples through a pre-trained multi-task diffusion model. This process aims to reduce classification errors caused by random patch masking. The experimental results on four time series datasets show that the proposed MDGPS model consistently surpasses other methods, achieving the highest classification accuracy and F1-score across all datasets: 95.81%, 87.64%, 82.31%, and 100% in accuracy; and 95.21%, 82.32%, 78.57%, and 100% in F1-Score for Epilepsy, FD-B, Gesture, and EMG, respectively. In addition, evaluations in a reinforcement learning scenario confirm MDGPS’s superior performance. Ablation and visualization experiments further validate the effectiveness of its individual components.